#P4246. [SHOI2008] 堵塞的交通
[SHOI2008] 堵塞的交通
Description
One day, due to some kind of time-travel phenomenon, you arrived in the legendary land of tiny people. Its layout is quite peculiar: the entire country's transportation network can be seen as a rectangular grid with rows and columns. Each point on the grid represents a city, and there is a road between adjacent cities. Thus there are cities and roads in total.
The traffic situation is terrible. Sometimes, due to congestion, the road between two cities becomes disconnected; it will not be passable again until the congestion clears. As a newcomer, you volunteer to help at the Ministry of Transport. Hearing that you come from a highly advanced world, the minister gladly asks you to write a query response system to save the ailing transportation network. The ministry will provide some traffic information, and your task is to answer queries based on the current traffic situation. The information comes in the following formats:
Close r1 c1 r2 c2: the road between the two adjacent cities and is blocked.Open r1 c1 r2 c2: the road between the two adjacent cities and is unblocked.Ask r1 c1 r2 c2: ask whether cities and are connected. If there exists a path that connects the two cities, returnY; otherwise returnN.
Note: denotes the row index and denotes the column index, with and .
Input Format
The first line contains a single integer , the number of columns in the grid. The following lines each contain one traffic instruction, and a single line Exit marks the end of input. Initially, all roads are assumed to be blocked. It is guaranteed that and the number of instructions .
Output Format
For each query, output a single Y or N.
2
Open 1 1 1 2
Open 1 2 2 2
Ask 1 1 2 2
Ask 2 1 2 2
Exit
Y
N
Hint
Constraints:
For of the testdata, , and number of instructions .
Translated by ChatGPT 5
京公网安备 11011102002149号