Network | 프로그래밍의 벗 PivotOJ
PivotOJ

Network

시간 제한: 2000ms메모리 제한: 1024MB출처: NOI 2023 QualificationBOJ 28494

문제

Rui Yuan the Duck is building a new network to run all of his new applications. This network is comprised of nn servers numbered from 11 to nn. There are also n1n - 1 network links, numbered from 11 to n1n - 1 connecting these servers.

The ii-th of these links connects servers u[i]u[i] and v[i]v[i] bidirectionally. It is guaranteed that it is possible to travel from any server to any other server using only the servers and network links.

Initially, all nn servers are active. Rui Yuan has mm applications running, which have distinct IDs from 11 to mm. Each application has 22 databases. Application jj has databases in servers a[j]a[j] and b[j]b[j] (which may be the same server). It is possible for two different applications to have a database on the same server.

In order for application jj to work, both of its databases must be connected through network links and active servers. To be precise, application jj is working if both of the following conditions are met:

  • Servers a[j]a[j] and b[j]b[j] are both active.
  • One can travel from server a[j]a[j] to server b[j]b[j] using only network links and active servers.

Rui Yuan has asked Benson the Rabbit to test his network. Using his hacking skills, Benson can select any set of servers and deactivate all of them simultaneously. The robustness of the network is the minimum number of servers that must be deactivated to ensure all mm applications are not working.

Benson is very busy, so he wants you to help him compute the robustness of the network and the selection of servers he should deactivate so that he doesn’t waste time deactivating more servers than needed.

입력

The first line of input contains two integers, nn and mm.

n1n - 1 lines will follow. The ii-th line contains two integers, u[i]u[i] and v[i]v[i] respectively, which are the servers connected by the ii-th network link.

Another mm lines will follow. The jj-th line contains two integers, a[j]a[j] and b[j]b[j] respectively, which are the servers storing the databases for application jj.

출력

Output two lines. The first line should contain a single integer, representing the robustness of the network, which we will denote as xx.

The second line should contain xx integers, representing the servers that should be deactivated. All xx integers must be pairwise distinct. You may output them in any order.

예제

예제 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
출력
2
4 2

예제 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

예제 3

입력
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

예제 4

입력
6 2
1 2
1 3
1 4
1 5
1 6
2 2
5 6
출력
2
2 1
코드를 제출하려면 로그인하세요.