#P2978. [USACO10JAN] Tea Time S

[USACO10JAN] Tea Time S

Description

N(1N1000)N (1 \leq N \leq 1000) cows, conveniently numbered 1N1 \dots N all attend a tea time every day. M(1M2,000)M (1 \leq M \leq 2,000) unique pairs of those cows have already met before the first tea time. Pair ii of these cows who have met is specified by two differing integers AiA_i and BiB_i (1AiN,1BiN1 \leq A_i \leq N, 1 \leq B_i \leq N). The input never indicates that cows have met each other more than once.

At tea time, any cow ii and cow jj who have met a mutual friend cow kk will meet sometime during that tea time and thus expand their circle of known cows.

Determine whether Q(1Q100)Q (1 \leq Q \leq 100) pairs of cows have met after tea times are held for long enough that no new cow meetings are occurring. Query jj consists of a pair of different cows XjX_j and YjY_j (1XjN,1YjN1 \leq X_j \leq N, 1 \leq Y_j \leq N).

For example, suppose that out of cows 11 through 55, we know that 22 has met 55, 22 has met 33, and 44 has met 55; see (a) below.

   2---3           2---3            2---3
    \              |\  |            |\ /|
1    \     -->  1  | \ |    -->  1  | X |
      \            |  \|            |/ \|
   4---5           4---5            4---5
    (a)             (b)              (c)

In the first tea time, cow 22 meets cow 44, and cow 33 meets cow 55; see (b) above. In the second tea time, cow 33 meets cow 44; see (c) above.

Input Format

Line 11: Three space-separated integers: NN, MM, and QQ.

Lines 2M+12 \dots M+1: Line i+1i+1 contains two space-separated integers: AiA_i and BiB_i.

Lines M+2M+Q+1M+2 \dots M+Q+1: Line j+M+1j+M+1 contains query jj as two space-separated integers: XjX_j and YjY_j.

Output Format

Lines 1Q1 \dots Q: Line jj should be Y if the cows in the jj-th query have met and N if they have not met.

5 3 3 
2 5 
2 3 
4 5 
2 3 
3 5 
1 5 

Y 
Y 
N