#P11194. [COTS 2021] 县 Županije
[COTS 2021] 县 Županije
Background
Translated from Izborne Pripreme 2021 (Croatian IOI/CEOI Team Selection) D1T3。。
2025/07/06: Added two sets of hack testdata and rejudged (contributor
Problem Description
You are given a tree with vertices. These vertices have already been partitioned into counties.
Now you need to choose a county seat for each county. Let the county that vertex belongs to be , and let the county seats be (they must be pairwise distinct). Then the following condition must hold:
- ,$\displaystyle \operatorname{dist}(i,A_{B_i})\lt \min_{j=1,j\neq B_i}^K \operatorname{dist}(i,A_j)$。
Here, is defined as the number of edges on the simple path between and .
In other words, for every vertex, its distance to the county seat of its own county must be strictly less than its distance to any other county seat.
Determine whether this can be achieved. If it can, output one valid construction.
Input Format
The first line contains two positive integers .
The second line contains integers .
The next lines each contain two positive integers , describing a tree edge .
Output Format
If it is feasible, output DA (Croatian for “yes”) on the first line. On the second line, output integers, where the -th integer is the county seat of the -th county.
Otherwise, output NE (Croatian for “no”).
3 2
1 1 2
1 2
2 3
DA
2 3
4 3
1 2 2 3
1 2
2 3
3 4
NE
8 3
1 2 1 2 2 1 3 3
1 2
1 3
2 4
2 5
3 6
3 7
7 8
DA
1 2 8
Hint
Sample Explanation
The figure below shows the explanation for sample .

Constraints
【Scoring】If you answer the first question correctly, you can get of the score. However, you must ensure the output format is correct. That is, if you only plan to answer the first question, you still need to output distinct integers in on the second line.
For of the testdata, it is guaranteed that , and the input is a tree.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| Yes | |||
| None |
Special property: every vertex has degree or 。
Translated by ChatGPT 5