Hedge Mazes
Time limit1sMemory limit128 MB
For each query (S,T) decide whether the undirected graph has exactly one simple path between S and T, and print Y or N per query.
- Level
Hard8 of 10
- Topics
- Graph, DFS, Greedy, Implementation
- Solved
- No attempts yet
Problem
The Queen of Nlogonia is a fan of mazes, so the queendom's architects built several mazes around the Queen's palace. Every maze is made of rooms connected by corridors. Each corridor connects a different pair of distinct rooms and can be traversed in both directions.
The Queen loves to stroll through a maze's rooms and corridors in the late afternoon. Her servants choose a different challenge every day: finding a simple path from a start room to an end room in a maze. A simple path is a sequence of distinct rooms such that each pair of consecutive rooms in the sequence is connected by a corridor. The first room of the sequence must be the start room, and the last room must be the end room. The Queen thinks a challenge is good when, among the routes from the start room to the end room, exactly one of them is a simple path. Can you help the Queen's servants choose a challenge that pleases the Queen?
To do so, write a program that, given the description of a maze and a list of queries defining start and end rooms, determines for each query whether that choice of rooms is a good challenge or not.
Input
The input consists of several test cases. The first line of each test case contains three integers , , and , representing respectively the number of rooms in a maze (), the number of corridors (), and the number of queries (). Rooms are identified by distinct integers from to . Each of the next lines describes a corridor with two distinct integers and , indicating a corridor connecting rooms and (). Each of the following lines describes a query with two distinct integers and , indicating the start and end rooms of a challenge (). Within each test case there is at most one corridor connecting each pair of rooms, and no two queries are the same.
The last test case is followed by a line containing three zeros.
Output
For each test case output lines. In the -th line write the answer to the -th query. If the rooms make a good challenge, write the uppercase character Y. Otherwise write the uppercase character N. After each test case, print a line containing a single hyphen character (-).