Circuit Counting
Time limit2sMemory limit256 MB
Count the nonempty subsets of up to 40 given plane vectors whose sum is the zero vector.
- Level
Medium6 of 10
- Topics
- Divide and conquer, Hash map
- Solved
- No attempts yet
Problem
You are given integer vectors in the plane. Start at the origin and treat each vector as a displacement from the previous position; the positions you visit form a path. For example, the vectors (1, 2), (2, 3), (-3, -5) form the path (0, 0), (1, 2), (3, 5), (0, 0). A path that ends at the origin is a circuit, so the path just described is a circuit.
You can form a path from any nonempty subset of the vectors, and whether the result is a circuit does not depend on the order in which the subset is used. Count the nonempty subsets that form circuits.
For example, take the vectors {(1, 2), (-1, -2), (1, 1), (-2, -3), (-1, -1)}. Exactly 4 of their subsets form circuits.
- {(1, 2), (-1, -2)}
- {(1, 1), (-1, -1)}
- {(1, 2), (1, 1), (-2, -3)}
- {(1, 2), (-1, -2), (1, 1), (-1, -1)}
Input
The first line contains the number of vectors ().
Each of the next lines contains two integers and separated by a space, describing the vector (, , ).
All given vectors are distinct.
Output
Print the number of nonempty subsets of the given vectors that form circuits. The answer is guaranteed to be smaller than .