#P8854. [POI 2002 R1] 超级马

    ID: 9870 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2002POI(波兰)广度优先搜索 BFS剪枝

[POI 2002 R1] 超级马

Problem Description

On an infinite chessboard, there is a super knight that can perform various moves.

Each move consists of two integers. The first number indicates how many squares it moves up or down, and the second number indicates how many squares it moves left or right. Move the knight to perform this move. (Positive numbers mean moving to the right, and negative numbers mean moving to the left.)

For each given super knight, determine whether it can reach every position on the chessboard.

Input Format

The first line contains an integer KK, the number of test cases.

For each test case, the first line contains an integer NN, the number of moves the super knight can perform.

The next NN lines each contain two integers PP and QQ, describing one move.

Output Format

Output KK lines. If the super knight can reach every position on the chessboard, output TAK, otherwise output NIE.

2
3
1 0
0 1
-2 -1
5
3 4
-3 -6
2 -2
5 6
-1 4
TAK
NIE

Hint

Constraints: 1K,N1001 \le K,N \le 100, 100P,Q100-100 \le P,Q \le 100.

Translated by ChatGPT 5