P27562 [洛谷] [NOISG 2023 Qualification] Network
入门
题目描述

Problem Description

Duck Rui Yuan has $n$ servers and $n-1$ bidirectional data lines, where the $i$-th data line bidirectional connects servers $u_i$ and $v_i$. It is guaranteed that for all $1 \le i \not = j \le n$, one can reach server $j$ from server $i$ and vice versa through the data lines.

Rui Yuan also has $m$ applications running, with the $j$-th application distributed across servers $a_j$ and $b_j$.

Initially, all servers are in the running state.

The $j$-th application can run if either of the following conditions is met:

  • Both $a_j$ and $b_j$ are running servers.

  • $a_j$ and $b_j$ can be connected through data lines and running servers.

Rui Yuan wants you to determine the minimum number of servers that need to be shut down to stop all applications from running.

Input Format

The first line contains two integers $n$ and $m$.

The next $n-1$ lines each contain two integers $u_i$ and $v_i$.

The next $m$ lines each contain two integers $a_j$ and $b_j$.

Output Format

The first line contains an integer $x$, the minimum number of servers to shut down.

The next $x$ lines each contain an integer, representing the IDs of the servers to shut down.

Sample Input and Output

Input Sample #1

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

Output Sample #1

2
4 2

Input Sample #2

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

Output Sample #2

4
3 2 4 1

Input Sample #3

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

Output Sample #3

2
4 6

Input Sample #4

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

Output Sample #4

2
2 1

Notes

Data Range

Subtask Points Special Conditions
$0$ $0$ Examples
$1$ $4$ $a_i=b_i$
$2$ $17$ $u_i=i, v_i=i+1$
$3$ $14$ $n, m \le 15$
$4$ $29$ $n, m \le 2000$
$5$ $36$ None

For $100\%$ of the data, $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$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
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