#P11170. 「CMOI R1」图上交互题 / Constructive Minimum Xor Path

    ID: 12476 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学图论2024洛谷原创Special JudgeO2优化构造Ad-hoc

「CMOI R1」图上交互题 / Constructive Minimum Xor Path

Background

On January 13, 2024, 15:59:31, as the last submission for interactive Problem J came back with a Wrong Answer, Little G’s EC-Final contest ended, which also meant his first time failing to get a medal in his ICPC career.

After reflecting on it, Little G decided to mass-produce interactive problems for himself to practice. How do you mass-produce interactive problems? As long as there are several unknowns aia_i in a data structure, and for each query you give a vector xx, the interactive library returns a function f(x)f(x) related to aia_i, then you can mass-produce interactive problems!

Then why is this problem not an interactive problem?

Problem Description

You are given an undirected graph with nn vertices and mm edges. The ii-th edge (ui,vi)(u_i, v_i) has an unknown edge weight aia_i.

For any path, define its cost as follows. Let the path be (p0,p1,...,pk)(p_0, p_1, ..., p_k), where (pi1,pi)(p_{i-1}, p_i) must be an edge in the undirected graph, and suppose it is the eie_i-th edge. Then the cost of the path is i=1kaei\bigoplus\limits_{i=1}^{k} a_{e_i}. Here, \bigoplus denotes XOR. (The path may pass through repeated vertices and repeated edges, i.e., pp and ee may contain repeated numbers.)

Define f(x,y)f(x, y) as the minimum cost among all paths from xx to yy. In particular, when x=yx = y, f(x,y)=0f(x, y) = 0.

Given n,mn, m, and for each edge (ui,vi)(u_i, v_i) the value f(ui,vi)f(u_i, v_i), you need to determine whether there exists a valid set of aia_i. If a solution exists, you also need to construct one.

Input Format

The first line contains two positive integers n,mn, m.

Lines 22 to m+1m + 1 each contain two positive integers ui,viu_i, v_i and a non-negative integer f(ui,vi)f(u_i, v_i).

Note: This problem does not guarantee that the graph is connected; there may be multiple edges and self-loops.

Output Format

If no solution exists, output only No.

Otherwise, output Yes on the first line, and output mm non-negative integers aia_i on the second line representing one valid solution.

There may be many valid answers; in that case, output any one. You must ensure that 0ai<2630 \le a_i < 2^{63}.

3 3
1 2 2
2 3 3
3 1 1
Yes
2 3 114514
1 1
1 1 1
No

Hint

Sample Explanation

The graph corresponding to the output answer is as follows:

Consider f(1,2)f(1, 2):

  • Consider the path 121 \rightarrow 2, whose cost is 22.

  • Consider the path $1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2$, whose cost is 231145142=1145132 \oplus 3 \oplus 114514 \oplus 2 = 114513.

There are also other paths, but it can be proven that there is no path with cost smaller than 22, so f(1,2)=2f(1, 2) = 2.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Special Property Score
11 A solution is guaranteed to exist. 2020
22 mn+10m \le n + 10 3030
33 5050

For 100%100\% of the testdata, 1n,m5×1051 \le n, m \le 5 \times 10^5, 1ui,vin1 \le u_i, v_i \le n, 0f(ui,vi)<2310 \le f(u_i, v_i) < 2^{31}.

Translated by ChatGPT 5