Logo
(追記) (追記ここまで)

24942번 - Jail 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB121312626.531%

문제

In JOI Kingdom, the security of IOI Jail is strictly controlled. There are $N$ rooms in IOI Jail, numbered from 1ドル$ to $N$. There are $N - 1$ passages connecting rooms. The passage $i$ (1ドル ≤ i ≤ N - 1$) connects the room $A_i$ and the room $B_i$ bidirectionally. It is possible to move from any room to any other room by passing through several passages.

There are $M$ prisoners in IOI Jail. Each prisoner has a “ID number”, which is an integer between 1ドル$ and $M,ドル inclusive. The bedroom of the prisoner $j$ (1ドル ≤ j ≤ M$) is the room $S_j,ドル and the workroom of the prisoner $j$ is the room $T_j$. 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 $M$ 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 $N$ in IOI Jail.
  • Information on the passages in IOI Jail $(A_1, B_1),ドル $(A_2, B_2),ドル $\cdots,ドル $(A_{N-1}, B_{N-1})$.
  • The number of prisoners $M$ in IOI Jail.
  • Information on the bedrooms and the workrooms of the prisoners $(S_1, T_1),ドル $(S_2, T_2),ドル $\cdots,ドル $(S_M, T_M)$.

The format of the input data is as follows. Given values are all integers.

$Q$

(Input for Scenario 1ドル$)

(Input for Scenario 2ドル$)

. . .

(Input for Scenario $Q$)

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 $Q$ lines to the standard output.

The $k$-th line (1ドル ≤ k ≤ Q$) should contain the following.

  • Yes if it is possible to move the prisoners for the scenario $k$.
  • No if it is not possible to move the prisoners for the scenario $k$.

제한

  • 1ドル ≤ Q ≤ 1,000円$.
  • 2ドル ≤ N ≤ 120,000円$.
  • 1ドル ≤ A_i < B_i ≤ N$ (1ドル ≤ i ≤ N - 1$).
  • 2ドル ≤ M ≤ N$.
  • 1ドル ≤ S_j ≤ N$ (1ドル ≤ j ≤ M$).
  • 1ドル ≤ T_j ≤ N$ (1ドル ≤ j ≤ M$).
  • $S_1, S_2, \cdots , S_M$ are different from each other.
  • $T_1, T_2, \cdots , T_M$ are different from each other.
  • $S_j \ne T_j$ (1ドル ≤ j ≤ M$).
  • It is possible to move from any room to any other room by passing through several passages.
  • The sum of $N$ for the $Q$ scenarios is less than or equal to 120ドル,000円$.

서브태스크

번호배점제한
15

$A_i = i,ドル $Bi = i + 1$ (1ドル ≤ i ≤ N - 1$).

25

$Q ≤ 20,ドル $N ≤ 250,ドル $M = 2$.

316

$Q ≤ 20,ドル $N ≤ 250,ドル $M ≤ 6$.

428

$Q ≤ 20,ドル $N ≤ 250,ドル $M ≤ 100$.

512

$Q ≤ 20,ドル $M ≤ 500$.

611

It is possible to move from any room to any other room by passing through at most 20ドル$ passages.

723

No additional constraints.

예제 입력 1

1
8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
2
3 4
4 8

예제 출력 1

Yes

For this sample input, if the director gives the following directions, it is possible to move the prisoners so that every prisoner takes a shortest path.

  1. Move the prisoner 2ドル$ from the room 4ドル$ to the room 5ドル$.
  2. Move the prisoner 1ドル$ from the room 3ドル$ to the room 4ドル$.
  3. Move the prisoner 2ドル$ from the room 5ドル$ to the room 6ドル$.
  4. Move the prisoner 2ドル$ from the room 6ドル$ to the room 7ドル$.
  5. Move the prisoner 2ドル$ from the room 7ドル$ to the room 8ドル$.

Therefore, output Yes. The structure of the jail for this sample input is as follows.

This sample input satisfies the constraints of all the subtasks.

예제 입력 2

2
7
1 2
2 3
3 4
4 5
3 6
6 7
2
4 1
5 7
4
1 2
1 3
1 4
3
2 3
3 4
4 2

예제 출력 2

Yes
No

There are $Q = 2$ scenarios. For Scenario 1ドル,ドル if the director gives the following directions, it is possible to move the prisoners so that every prisoner takes a shortest path.

  1. Move the prisoner 1ドル$ from the room 4ドル$ to the room 3ドル$.
  2. Move the prisoner 1ドル$ from the room 3ドル$ to the room 2ドル$.
  3. Move the prisoner 2ドル$ from the room 5ドル$ to the room 4ドル$.
  4. Move the prisoner 2ドル$ from the room 4ドル$ to the room 3ドル$.
  5. Move the prisoner 2ドル$ from the room 3ドル$ to the room 6ドル$.
  6. Move the prisoner 1ドル$ from the room 2ドル$ to the room 1ドル$.
  7. Move the prisoner 2ドル$ from the room 6ドル$ to the room 7ドル$.

However, for Scenario 2ドル,ドル it is not possible to move the prisoners so that every prisoner takes a shortest path. Therefore, the first line of output should be Yes, and the second line of output should be No.

This sample input satisfies the constraints of Subtasks 3, 4, 5, 6, 7.

예제 입력 3

3
3
1 2
2 3
2
2 1
3 2
7
1 2
2 3
3 4
4 5
5 6
6 7
3
1 3
4 2
2 5
8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
4
1 5
2 6
3 7
4 8

예제 출력 3

Yes
No
Yes

This sample input satisfies the constraints of Subtasks 1, 3, 4, 5, 6, 7.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2021/2022 Spring Training Camp 1-1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /