#P2978. [USACO10JAN] Tea Time S
[USACO10JAN] Tea Time S
Description
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 Format
Line : Three space-separated integers: , , and .
Lines : Line contains two space-separated integers: and .
Lines : Line contains query as two space-separated integers: and .
Output Format
Lines : Line should be Y if the cows in the -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
京公网安备 11011102002149号