#P4246. Little Nation Traffic System
Little Nation Traffic System
Little Nation Traffic System
You have unexpectedly found yourself in the fabled Little Nation, a country whose road network forms a 2 \times C grid. There are a total of \(2C\) cities and \(3C-2\) roads connecting these cities. Two cities are adjacent if they are horizontally or vertically neighboring. Initially, all roads are open.
The transportation department provides a series of commands to update or query the status of the roads due to occasional traffic jams. There are three types of commands:
Close r1 c1 r2 c2
: Block the road between two adjacent cities \((r_1, c_1)\) and \((r_2, c_2)\).Open r1 c1 r2 c2
: Reopen the road between two adjacent cities \((r_1, c_1)\) and \((r_2, c_2)\).Ask r1 c1 r2 c2
: Query if there is a path connecting city \((r_1, c_1)\) and city \((r_2, c_2)\). OutputY
if connected, otherwise outputN
.
Note: \(1 \le r_i \le 2\) and \(1 \le c_i \le C\).
inputFormat
The first line contains two integers \(C\) and \(Q\), where \(C\) is the number of columns in the grid and \(Q\) is the number of commands. The following \(Q\) lines each contain one command in one of the following forms:
Close r1 c1 r2 c2
Open r1 c1 r2 c2
Ask r1 c1 r2 c2
It is guaranteed that the two cities specified in each command are adjacent in the grid.
outputFormat
For each Ask
command, output a single line containing Y
if the two specified cities are connected by open roads, or N
otherwise.
sample
3 10
Ask 1 1 2 3
Close 1 2 2 2
Ask 1 1 2 3
Close 2 2 2 3
Ask 1 1 2 3
Close 1 3 2 3
Ask 1 1 2 3
Open 1 2 2 2
Open 2 2 2 3
Ask 1 1 2 3
Y
Y
Y
N
Y
</p>