#P5983. [PA 2019] Osady i warownie 2
[PA 2019] Osady i warownie 2
Description
An grid is given. The rows are numbered from to from top to bottom, and the columns are numbered from to from left to right. Initially, every cell is not an obstacle.
A path from the start to the end is defined to be valid if and only if it passes through exactly cells (including the start and the end), and each step moves either one cell to the right or one cell downward. Of course, the path cannot pass through obstacle cells (including the start and the end).
You have an variable . You need to simulate operations. Each operation gives three non-negative integers . Let , :
- If is an obstacle cell, ignore this operation and output
NIE. - Otherwise, if after turning into an obstacle cell there still exists a valid path, then turn into an obstacle cell and output
NIE. - Otherwise, if after turning into an obstacle cell there is no valid path, then output
TAK, and update to .
Input Format
The first line contains three positive integers .
The next lines each contain three non-negative integers .
Output Format
For each operation, output one line: TAK or NIE.
3 5 7
0 1 123
1 0 0
4 8 0
2 2 16
2 3 0
18 19 17
3 0 0
NIE
TAK
NIE
TAK
NIE
TAK
NIE
Hint
For of the testdata: , , .
Explanation:

Translated by ChatGPT 5
京公网安备 11011102002149号