#P10731. [NOISG 2023 Qualification] Network

[NOISG 2023 Qualification] Network

Problem Description

Duck Rui Yuan has nn servers and n1n-1 bidirectional data cables. The ii-th cable connects uiu_i and viv_i in both directions. It is guaranteed that for all 1ijn1 \le i \not = j \le n, you can reach server jj from server ii through the cables, and vice versa.

Rui Yuan also has mm applications running. The jj-th application runs on two servers, aja_j and bjb_j.

Initially, all servers are running.

The jj-th application can run if both of the following conditions hold:

  • Both aja_j and bjb_j are running servers.

  • Between aja_j and bjb_j, there is a connection through data cables and running servers.

Rui Yuan wants you to find the minimum number of servers that must be stopped so that all applications stop running.

Input Format

The first line contains two integers n,mn,m.

The next n1n-1 lines each contain two integers ui,viu_i,v_i.

The next mm lines each contain two integers aj,bja_j,b_j.

Output Format

The first line contains an integer xx, the minimum number of servers that must be stopped.

The next 11 line contains xx integers, the indices of the servers to be stopped. All xx integers must be distinct. You may output them in any order.

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

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

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

Hint

Constraints

Subtask\text{Subtask} Score Special Property
00 Sample
11 44 ai=bia_i=b_i
22 1717 ui=i,vi=i+1u_i=i,v_i=i+1
33 1414 n,m15n,m\le15
44 2929 n,m2000n,m\le2000
55 3636 None

For 100%100\% of the testdata, $1 \le n,m \le 200000, 1 \le u_i,v_i \le n, u_i\not = v_i, 1 \le a_j,b_j\le n$.

Translated by ChatGPT 5