#P11170. 「CMOI R1」图上交互题 / Constructive Minimum Xor Path
「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 in a data structure, and for each query you give a vector , the interactive library returns a function related to , 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 vertices and edges. The -th edge has an unknown edge weight .
For any path, define its cost as follows. Let the path be , where must be an edge in the undirected graph, and suppose it is the -th edge. Then the cost of the path is . Here, denotes XOR. (The path may pass through repeated vertices and repeated edges, i.e., and may contain repeated numbers.)
Define as the minimum cost among all paths from to . In particular, when , .
Given , and for each edge the value , you need to determine whether there exists a valid set of . If a solution exists, you also need to construct one.
Input Format
The first line contains two positive integers .
Lines to each contain two positive integers and a non-negative integer .
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 non-negative integers on the second line representing one valid solution.
There may be many valid answers; in that case, output any one. You must ensure that .
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 :
-
Consider the path , whose cost is .
-
Consider the path $1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2$, whose cost is .
There are also other paths, but it can be proven that there is no path with cost smaller than , so .
Constraints
This problem uses bundled testdata.
| Special Property | Score | |
|---|---|---|
| A solution is guaranteed to exist. | ||
For of the testdata, , , .
Translated by ChatGPT 5