RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00559

Pastiri

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Croatian Olympiad in Informatics
October \(3^{rd}\) 2020
\(I\) never felt \(so\) full that \(I\) couldn’t eat one more lamb.” – Mr. Malnar
A flock of \(K\) sheep lives in a tree, a simple connected graph without a cycle. The tree contains \(N\) nodes
denoted with integers from 1 to \(N\). Each node of a tree is a home to at most one sheep. A wise shepherd
realized that, sooner or later, wolves will learn how to climb trees.
In order to protect the sheep, we need to place shepherds into some nodes such that each sheep is protected
by at least one shepherd. It is known that each shepherd protects all sheep that are closest to
him, and only them. The distance between some sheep and some shepherd is equal to the number of
nodes on a unique path between the node containing the sheep and the node containing the shepherd
(inclusive). Additionally, the shepherd can share a node with a sheep. Of course, in that case he protects
only that sheep.
Determine the minimal number of shepherds that need to placed in the nodes of a tree such that
each sheep is protected by at least one shepherd. Additionally, determine one such arrangement of
shepherds.

제약

Subtask
Score
Constraints
1
8
\(1 \le N \le 500\,000\), every node \(x = 1\), . . . , \(n - 1\) is connected with node \(x + 1\)
2
18
\(1 \le K \le 15\), \(1 \le N \le 500\,000\)
3
23
\(1 \le N \le 2\,000\)
4
51
\(1 \le N \le 500\,000\)
3 od 8
Croatian Olympiad in Informatics
October \(3^{rd}\) 2020

입력 형식

The first line contains integers \(N\) and \(K\) (\(1 \le K \le N\)) from the task description.
Each of the next \(N - 1\) lines contains two integers \(a_{i}\) and \(b_{i}\) (\(1 \le a_{i}\), \(b_{i} \le N\)) which indicate that there is
an undirected edge between nodes \(a@@RISE_MATH_BLOCK_0@@i\).
The next line contains \(K\) different integers \(o_{i}\) (\(1 \le o_{i} \le N\)) that represent nodes which containing a sheep.

출력 형식

In the first line you should output a number \(X\) which represents the minimal number of shepherds from
the task description.
In the second line you should output \(X\) spa\(ce-se\)parated integers which represent the nodes containing
shepherds.
If there are multiple correct solutions, you may output any of them.

예제 1
입력
4 2
1 2
2 3
3 4
1 4
출력
2
1 3
예제 2
입력
9 5
1 2
2 3
3 4
3 5
1 6
1 7
7 8
8 9
2 5 6 7 9
출력
3
1 4 9
예제 3
입력
20 9
1 2
2 3
2 4
4 5
4 6
5 7
7 8
8 9
7 10
10 11
6 12
6 13
6 17
13 14
14 15
14 16
17 18
18 19
18 20
1 3 9 11 12 15 16 19 20
출력
3
5 14 18
설명

Clarification of the third example:
4 od 8

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2019/2020 Olympiad

평가 및 의견

Pastiri

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Pastiri

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8