Jail
시간 제한4초메모리 제한1024 MB
트리와 M명의 죄수 출발/도착 쌍이 주어질 때, 두 명이 같은 방을 쓰지 않고 한 명씩 최단 경로로 이동하도록 만들 수 있는지 판정한다.
문제
In JOI Kingdom, the security of IOI Jail is strictly controlled. There are rooms in IOI Jail, numbered from to . There are passages connecting rooms. The passage () connects the room and the room bidirectionally. It is possible to move from any room to any other room by passing through several passages.
There are prisoners in IOI Jail. Each prisoner has a “ID number”, which is an integer between and , inclusive. The bedroom of the prisoner () is the room , and the workroom of the prisoner is the room . A prisoner may work in the bedroom of another prisoner. However, no two prisoners share the same bedroom, and no two prisoners share the same workroom.
One morning, the prisoners have to move from their bed rooms to their work rooms. Mr. APIO is the director of IOI Jail. He will give the following directions to the prisoners to move.
Direction Choose a prisoner, and move the chosen prisoner from the current room to another room which is connected with the current room by a passage. In order to avoid communication between prisoners, it is not allowed to move the prisoner to a room where another prisoner stays.
In order to start work as early as possible, Mr. APIO wants to know whether it is possible to give directions so that every prisoner does not pass through the same room more than once (it means that every prisoner takes a shortest path).
Write a program which, given information of the rooms and the passages in IOI Jail and information on the prisoners, determines whether it is possible to move the prisoners so that every prisoner takes a shortest path.
입력
A test case consists of Q scenarios, numbered from 1 to Q. The following values are specified for each scenario. For the range of these values, see Constraints.
- The number of rooms in IOI Jail.
- Information on the passages in IOI Jail , , , .
- The number of prisoners in IOI Jail.
- Information on the bedrooms and the workrooms of the prisoners , , , .
The format of the input data is as follows. Given values are all integers.
(Input for Scenario )
(Input for Scenario )
. . .
(Input for Scenario )
The format of the input data for each scenario is as follows. See Sample Input and Output for details.
\begin{align\*}& N \\\ & A\_1\\,B\_1 \\\ & A\_2 \\, B\_2 \\, \\\ & \vdots \\\ & A\_{N-1} \\, B\_{N-1} \\\ & M \\\ & S\_1 \\, T\_1 \\\ & S\_2 \\, T\_2 \\\ & \vdots \\\ & S\_M \\, T\_M\end{align\*}
출력
Write lines to the standard output.
The -th line () should contain the following.
Yesif it is possible to move the prisoners for the scenario .Noif it is not possible to move the prisoners for the scenario .
제한
- .
- .
- ().
- .
- ().
- ().
- are different from each other.
- are different from each other.
- ().
- It is possible to move from any room to any other room by passing through several passages.
- The sum of for the scenarios is less than or equal to .