PDP-22 (2010) - Camp common - 4 (ttime)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal

TTIME

Problem

N\;(1 \le N \le 1000) cows, conveniently numbered 1 ... N all attend a tea time every day. M\;(1 \le M \le 2000) unique pairs of those cows have already met before the first tea time. Pair i of these cows who have met is specified by two differing integers A_i and B_i (1 \le A_i \le N; 1 \le B_i \le N). The input never indicates that cows have met each other more than once.

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

Determine whether Q\;(1 \le Q \le 100) pairs of cows have met after tea times are held for long enough that no new cow meetings are occurring. Query j consists of a pair of different cows X_j and Y_j (1 \le X_j \le N; 1 \le Y_j \le N).

For example, suppose that out of cows 1 through 5, we know that 2 has met 5, 2 has met 3, and 4 has met 5; 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 2 meets cow 4, and cow 3 meets cow 5; see (b) above. In the second tea time, cow 3 meets cow 4; see (c) above.

Input

In the first line of input, there will be three space separated integers N, M, and Q.

In the next 2 to M + 1 lines, line i+1 will contain two integers separated by a space: A_i and B_i

In the next M + 2 to M + Q + 1 lines, line j + M + 1 will contain query j as two integers separated by a space: X_j and Y_j

Output

The output will consist of the lines 1 to Q, where the j-th line should contain Y if the cows from the j-th query have met, or N otherwise.

Example of Input - Output Files:

STDIN (ttime.in)

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

STDOUT (ttime.out)

Y
Y
N
Constraints
  • 1 \le N \le 1000.
  • 1 \le M \le 2000.
  • 1 \le Q \le 100.
  • Maximum execution time: 1 sec.
  • Available memory : 64 MB.

Comments

There are no comments at the moment.