#P1556. [USACO12MAR] 幸福的路 Connect the Cows B
[USACO12MAR] 幸福的路 Connect the Cows B
Description
Every day, John bustles around to ensure the health and happiness of () cows.
Each cow’s position is given by a 2D coordinate, and John starts at the origin . To make the route more interesting, John decides to move only along directions parallel to the coordinate axes, that is, only north, south, east, or west. Moreover, John changes direction only upon reaching the coordinate of some cow (of course, if necessary, John may also pass through a cow’s coordinate without changing direction).
If John changes direction, he turns in place by or . John’s path must visit all cows and then return to the origin.
John may pass through any cow’s coordinate without changing direction any number of times. Please compute how many routes allow John to visit all cows, such that he changes direction exactly once at each cow’s coordinate. The same geometric path traversed in the opposite direction should be counted twice.
Input Format
The first line contains an integer , as described above.
The next lines each contain two space-separated integers and , where line gives the coordinates of the -th cow ().
Output Format
Output a single integer on one line, the number of valid routes (output 0 if there are no valid routes).
4
0 1
2 1
2 0
2 -5
2
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号