Bridges
Time limit1sMemory limit256 MB
Towns on two banks link east on the north side and west on the south side while bridges are added and roads close and queries ask if one town reaches another.
- Level
Hard8 of 10
- Topics
- Graph, Intervals, Binary search
- Solved
- No attempts yet
Problem
A river runs east-west with towns on the north bank ( to ) and on the south ( to ). On each bank, labels increase toward the east.
On the north bank, each town except has a one-way road to its eastern neighbor. On the south bank, each town except has a one-way road to its western neighbor.
Roads may be permanently closed. Bridges connect one north town to one south town, work in both directions, never break, never cross, and each town uses at most one bridge.
Initially all roads are open and no bridges exist. Process events in order:
A G1 G2: build a bridge between and .B G1 G2: close the one-way road between and .Q G1 G2: ask whether can reach with current roads and bridges.
Input
Line 1: () and ().
Next lines describe events. Town ids satisfy and differ. Closed roads were open before; built bridges did not exist before.
Output
For each Q event, print DA if a route exists, otherwise NE, in input order.