#P8854. Super Knight Reachability
Super Knight Reachability
Super Knight Reachability
On an infinite chessboard, a super knight can perform various moves. Each move is represented by a pair of integers: the first integer indicates a vertical movement (up or down) and the second integer indicates a horizontal movement (to the right if positive, and to the left if negative). The knight starts at position (0, 0).
The reachable positions for the knight are all integer linear combinations of the move vectors, i.e., the set of positions that can be described as
[ { c_1(a_1,b_1)+c_2(a_2,b_2)+\cdots+c_n(a_n,b_n) \mid c_i \in \mathbb{Z} } ]
This set forms a lattice in \(\mathbb{Z}^2\). The super knight can cover the entire chessboard (i.e. every point in \(\mathbb{Z}^2\)) if and only if the lattice it spans is exactly \(\mathbb{Z}^2\). A well-known necessary and sufficient condition is that the greatest common divisor (gcd) of all \(2\times 2\) determinants (formed by any two distinct move vectors) is 1.
For a case with only one move, the reachable positions form a one-dimensional subset, and thus the answer is always "No".
Given the set of moves for a super knight, determine if the knight can reach every cell on the infinite chessboard.
inputFormat
The input begins with an integer T (1 ≤ T ≤ 100), representing the number of test cases. Each test case is defined as follows:
- An integer n (1 ≤ n ≤ 100) specifying the number of moves available.
- Then follow n lines, each containing two space-separated integers a and b (|a|, |b| ≤ 109), where a is the vertical component (up if positive, down if negative) and b is the horizontal component (right if positive, left if negative) of a move.
outputFormat
For each test case, output a single line with either "Yes" if the super knight can reach every cell on the chessboard, or "No" otherwise.
sample
1
1
1 2
No
</p>