#P1444. [USACO1.3] 虫洞 wormhole
[USACO1.3] 虫洞 wormhole
Description
Farmer John's high-energy physics experiment over the weekend backfired, causing wormholes to appear on the farm, which is a two-dimensional plane. No two wormholes are at the same position.
According to his calculations, FJ knows the wormholes are paired up, forming pairs. For example, if wormholes and form a pair, any object entering wormhole will exit from wormhole with its direction unchanged, and vice versa.
However, this can lead to a rather unpleasant consequence. For instance, suppose there are two paired wormholes and , and Bessie starts at moving in the positive direction. Bessie will enter wormhole , exit from , then enter again, getting trapped in an infinite loop!
FJ knows the exact position of every wormhole on his farm. He knows Bessie always moves in the positive direction, although he does not remember Bessie's current position.
Please help FJ count how many pairing schemes of wormholes have the property that there exists a position such that if Bessie starts there, she will be trapped in an infinite loop.
Input Format
The first line contains a positive integer , the number of wormholes.
Each of the next lines contains two integers , the coordinates of a wormhole.
Output Format
Output a single integer, the answer.
4
0 0
1 0
1 1
0 1
2
Hint
Constraints
For 100% of the testdata, , .
It is guaranteed that is even.
Sample Explanation
Number the wormholes to . If we pair and , then if Bessie starts anywhere between and , she will fall into an infinite loop.
Similarly, with the same starting point, if the pairings are and , Bessie will also be trapped in a loop. (If Bessie enters through and exits from , she will move toward , then be teleported to , and finally return to .)
Only the pairing and allows Bessie to walk in the positive direction from any point in the plane without entering an infinite loop.
Problem statement translation from NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号