TTIME
Problem
cows, conveniently numbered all attend a tea time every day. unique pairs of those cows have already met before the first tea time. Pair of these cows who have met is specified by two differing integers and . The input never indicates that cows have met each other more than once.
At tea time, any cow and cow who have met a mutual friend cow will meet sometime during that tea time and thus expand their circle of known cows.
Determine whether pairs of cows have met after tea times are held for long enough that no new cow meetings are occurring. Query consists of a pair of different cows and .
For example, suppose that out of cows through , we know that has met , has met , and has met ; 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 meets cow , and cow meets cow ; see (b) above. In the second tea time, cow meets cow ; see (c) above.
Input
In the first line of input, there will be three space separated integers , , and .
In the next to lines, line will contain two integers separated by a space: and
In the next to lines, line will contain query as two integers separated by a space: and
Output
The output will consist of the lines to , where the -th line should contain if the cows from the -th query have met, or 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
- .
- .
- .
- Maximum execution time: sec.
- Available memory : MB.
Comments