#P3875. [TJOI2010] 被污染的河流

[TJOI2010] 被污染的河流

Description

Unfortunately, not long after, some unscrupulous business owners built factories and polluted the rivers. Many residents living by the rivers drank polluted water and became ill. The government sent an investigator, Xiaoqiang (pinyin), to examine the pollution. The geography expert Xiaoqiang acted quickly and soon produced a pollution report. The report lists the polluted river segments. All residents who can fetch water from any such segment may get sick (the endpoints of a segment are ignored). However, Xiaoqiang could not figure out exactly how many communities’ residents would become ill, so he has asked for your help.

Input Format

The first line contains an integer NN, the number of polluted river segments.

Each of the next NN lines contains 44 integers x1,y1,x2,y2x_1, y_1, x_2, y_2, giving the start and end positions of a polluted segment. The two positions on each line are guaranteed to be distinct and satisfy x1=x2x_1 = x_2 or y1=y2y_1 = y_2.

Output Format

Output a single integer AA, indicating that there are AA communities whose residents will drink polluted water.

3
1 3 4 3
6 7 6 3
4 6 7 6

16

Hint

  • For 10%10\% of the testdata, 1x1,y1,x2,y21001 \le x_1, y_1, x_2, y_2 \le 100, 1N1001 \le N \le 100.
  • For 30%30\% of the testdata, 1x1,y1,x2,y21041 \le x_1, y_1, x_2, y_2 \le 10^4, 1N1001 \le N \le 100.
  • For 100%100\% of the testdata, 1x1,y1,x2,y21051 \le x_1, y_1, x_2, y_2 \le 10^5, 1N1041 \le N \le 10^4.

Translated by ChatGPT 5