#P6696. [BalticOI 2020] 图 (Day2)
[BalticOI 2020] 图 (Day2)
Description
You have an undirected graph, and each edge has a color: red or black.
What you need to do is assign a real-valued weight to each node such that:
- For every black edge, the sum of the weights of its two endpoints is .
- For every red edge, the sum of the weights of its two endpoints is .
- The sum of the absolute values of all node weights is minimized.
Find one such assignment of node weights.
Input Format
The first line contains two integers , representing the number of nodes and the number of edges.
The nodes are numbered from to .
The next lines each contain three integers , describing an edge whose endpoints are and . If is , then this edge is black; if is , then this edge is red.
Output Format
If there is a solution, first output YES on the first line, then output integers on the second line representing one possible set of node weights.
If there are multiple solutions, output any one of them.
If there is no solution, output a single line containing the string NO.
4 4
1 2 1
2 3 2
1 3 2
3 4 1
YES
0.5 0.5 1.5 -0.5
2 1
1 2 1
YES
0.3 0.7
3 2
1 2 2
2 3 2
YES
0 2 0
3 4
1 2 2
2 2 1
2 1 1
1 2 2
NO
Hint
Judging Method
Your output is considered correct if and only if:
- For every edge, the error between the sum of the weights of its two endpoints and the required value for that edge is at most .
- The error between the sum of the absolute values of all node weights and the standard answer is at most .
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (5 pts): , .
- Subtask 2 (12 pts): .
- Subtask 3 (17 pts): .
- Subtask 4 (24 pts): .
- Subtask 5 (42 pts): no special restrictions.
For of the testdata, , .
This problem uses a Special Judge.
Translated by ChatGPT 5
京公网安备 11011102002149号