#P10665. [AMPPZ2013] Bytehattan

[AMPPZ2013] Bytehattan

Problem Description

Bytehattan has n×nn \times n grid points, forming a grid graph. At the beginning, the whole graph is complete.

There are kk operations. In each operation, an edge (u,v)(u,v) in the graph is deleted. You need to answer whether uu and vv are still connected after deleting this edge.

Input Format

The first line contains two positive integers n,k(2n1500,1k2n(n1))n,k(2\leq n\leq 1500,1\leq k\leq 2n(n-1)), representing the size of the grid graph and the number of operations.

The next kk lines describe the operations. Each line contains two pieces of information. Each piece of information contains two positive integers a,b(1a,bn)a,b(1\leq a,b\leq n) and a character cc (cc is N or E).

If cc is N, it means deleting the edge from (a,b)(a,b) to (a,b+1)(a,b+1). If cc is E, it means deleting the edge from (a,b)(a,b) to (a+1,b)(a+1,b).

The data is encrypted. For each operation, if the previous answer was TAK or this is the first operation, only consider the first piece of information; otherwise, only consider the second piece of information. The data guarantees that each edge is deleted at most once.

Output Format

Output kk lines. For each query, if the two endpoints are still connected, output TAK; otherwise output NIE.

3 4
2 1 E 1 2 N
2 1 N 1 1 N
3 1 N 2 1 N
2 2 N 1 1 N
TAK
TAK
NIE
NIE

Hint

Constraints: 2n15002\leq n\leq 1500, 1k2n(n1)1\leq k\leq 2n(n-1), 1a,bn1\leq a,b\leq n.

Translated by ChatGPT 5