Problem H
Reseplaneraren
Languages
en
sv
After using public transport for several years, you have
noticed that Bästtrafik’s route planning app is not very good.
It often suggests routes with 3 transfers, when you know that
the journey can be made without any transfers at all! To
demonstrate how incompetent they are, you will develop a
competing app that determines if it is possible to travel from
station
The public transport network in Gothenburg can be described
by its
Your app must now answer
Input
The first line of input contains the integers
The following
Next,
The final
Note that this problem has a very large input size. Therefore, it is recommended to use fast input reading.
Output
For each question, print "Yes" if it is possible to make the journey without transfers, otherwise print "No". Print these in the same order as the questions.
Scoring
Your solution will be tested on a set of test case groups. To earn points for a group, you must pass all test cases in that group.
Group |
Points |
Constraints |
|
|
|
|
|
|
|
|
|
|
|
For each query, |
|
|
No additional constraints. |
Explanation of Sample 1

-
Question 1: It is not possible to travel from station 1 to station 3 without a transfer. If transferring once were allowed, it would have been possible.
-
Question 2: There isn’t even a tram line going to station 4, so it is certainly not possible to make the journey without transfers.
-
Question 3: Here, we can take the tram line between stations 1 and 2.
-
Question 4: Here, we can take the tram line between stations 5 and 3.
Sample Input 1 | Sample Output 1 |
---|---|
5 2 4 1 2 2 3 3 4 3 5 1 2 2 5 1 3 4 3 1 2 5 3 |
No No Yes Yes |