Under construction

Still being built. Things may change

Hedge Mazes

Time limit1sMemory limit128 MB

Summary
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 RR, CC, and QQ, representing respectively the number of rooms in a maze (2≤R≤1042 \le R \le 10^4), the number of corridors (1≤C≤1051 \le C \le 10^5), and the number of queries (1≤Q≤10001 \le Q \le 1000). Rooms are identified by distinct integers from 11 to RR. Each of the next CC lines describes a corridor with two distinct integers AA and BB, indicating a corridor connecting rooms AA and BB (1≤A<B≤R1 \le A < B \le R). Each of the following QQ lines describes a query with two distinct integers SS and TT, indicating the start and end rooms of a challenge (1≤S<T≤R1 \le S < T \le R). 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 Q+1Q + 1 lines. In the ii-th line write the answer to the ii-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 (-).

Examples1

  1. Example 1

    Input
    6 5 3
    1 2
    2 3
    2 4
    2 5
    4 5
    1 3
    1 5
    2 6
    4 2 3
    1 2
    2 3
    1 4
    1 3
    1 2
    0 0 0
    
    Expected output
    Y
    N
    N
    -
    N
    Y
    Y
    -