#P11194. [COTS 2021] 县 Županije

    ID: 12356 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2021Special JudgeO2优化构造COCI(克罗地亚)

[COTS 2021] 县 Županije

Background

Translated from Izborne Pripreme 2021 (Croatian IOI/CEOI Team Selection) D1T3。2s,0.5G\texttt{2s,0.5G}

2025/07/06: Added two sets of hack testdata and rejudged (contributor

https://www.luogu.com.cn/user/482660

Problem Description

You are given a tree with NN vertices. These NN vertices have already been partitioned into KK counties.

Now you need to choose a county seat for each county. Let the county that vertex ii belongs to be BiB_i, and let the county seats be A1,A2,,AKA_1, A_2, \cdots, A_K (they must be pairwise distinct). Then the following condition must hold:

  • 1iN\forall 1\le i\le N,$\displaystyle \operatorname{dist}(i,A_{B_i})\lt \min_{j=1,j\neq B_i}^K \operatorname{dist}(i,A_j)$。

Here, dist(a,b)\mathrm{dist}(a,b) is defined as the number of edges on the simple path between aa and bb.

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 N,KN, K.

The second line contains NN integers B1,B2,,BNB_1, B_2, \cdots, B_N.

The next (N1)(N-1) lines each contain two positive integers u,vu, v, describing a tree edge (u,v)(u, v).

Output Format

If it is feasible, output DA (Croatian for “yes”) on the first line. On the second line, output KK integers, where the ii-th integer is the county seat of the ii-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 33.

Constraints

【Scoring】If you answer the first question correctly, you can get 40%40\% 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 KK distinct integers in [1,N][1, N] on the second line.

For 100%100\% of the testdata, it is guaranteed that 1BiKN2×1051\le B_i\le K\le N\le 2\times 10^5, and the input is a tree.

Subtask ID NN\le Special Property Score
1 1 20 20 None 10 10
2 2 2000 2\, 000 25 25
3 3 2×105 2\times 10^5 Yes 30 30
4 4 None 35 35

Special property: every vertex has degree 11 or 33

Translated by ChatGPT 5