#P16442. [XJTUPC 2026] 机房分配

    ID: 18473 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>Special Judge构造2026高校校赛

[XJTUPC 2026] 机房分配

Problem Description

To reduce the risk of cheating in programming contests, the school needs to assign nn contestants to kk computer labs for the contest.

It is known that some contestants are relatively familiar with each other. We use a weighted undirected graph G=(V,E)G=(V,E) to describe these relationships:

  • Each vertex represents a contestant.
  • Each edge represents that there is some relationship between two contestants.
  • The edge weight is a positive integer indicating how close their relationship is. A larger weight means they are more familiar with each other.
  • The graph GG is a simple graph with no self-loops and no multiple edges.

If the total relationship strength among contestants in the same lab is too high, it will increase the pressure on proctors.

For a certain lab, the sum of the weights of all edges whose both endpoints are assigned to this lab is called the risk value of this lab.

Let the sum of all edge weights in the whole graph be S=∑e∈EweS = \sum\limits_{e \in E} w_e, where wew_e denotes the weight of edge ee.

The school requires that the sum of the risk values of all labs must not exceed ⌈Sk⌉\left\lceil \frac{S}{k} \right\rceil.

Now you need to determine whether there exists an assignment such that:

  • Each contestant is assigned to exactly one lab.
  • The sum of the risk values of all labs does not exceed ⌈Sk⌉\left\lceil \frac{S}{k} \right\rceil.

If it exists, output one assignment that satisfies the requirements. If there are multiple valid assignments, output any one.

Note: It is allowed that a lab has no contestants assigned to it. The graph GG is not guaranteed to be connected.

Input Format

The first line contains three integers n,mn, m and kk ($1 \le k \le n \le 5\times 10^5, 0 \le m \le 5\times 10^5$), separated by spaces, representing the number of contestants, the number of relationships, and the number of computer labs.

The next mm lines each contain three integers u,vu, v and ww (1≤u,v≤n,u≠v,1≤w≤1091 \le u,v \le n, u \ne v, 1 \le w \le 10^9), separated by spaces, indicating an undirected edge of weight ww between contestant uu and contestant vv.

It is guaranteed that there are no multiple edges in the input graph.

Output Format

If there is no assignment that satisfies the requirements, output one line containing only the string No\tt{No}.

Otherwise output two lines:

  • The first line contains the string Yes\tt{Yes}.
  • The second line contains nn integers a1,a2,⋯ ,ana_1,a_2,\cdots,a_n (1≤ai≤k1 \le a_i \le k), separated by spaces, where aia_i indicates that contestant ii is assigned to lab aia_i.

If there are multiple valid assignments, output any one.

4 4 2
1 2 1
2 3 1
3 4 1
4 1 1
Yes
1 2 1 2 

Hint

Translated by ChatGPT 5