atcoder#ARC108C. [ARC108C] Keep Graph Connected
[ARC108C] Keep Graph Connected
Score : points
Problem Statement
Given is an undirected connected graph with vertices numbered to , and edges numbered to . The given graph may contain multi-edges but not self loops.
Each edge has an integer label between and (inclusive). Edge has a label , and it connects Vertex and bidirectionally.
Snuke will write an integer between and (inclusive) on each vertex (multiple vertices may have the same integer written on them) and then keep only the edges satisfying the condition below, removing the other edges.
Condition: Let and be the integers written on the vertices that are the endpoints of the edge. Exactly one of and equals the label of the edge.
We call a way of writing integers on the vertices good if (and only if) the graph is still connected after removing the edges not satisfying the condition above. Determine whether a good way of writing integers exists, and present one such way if it exists.
Constraints
- The given graph is connected and has no self-loops.
Input
Input is given from Standard Input in the following format:
Output
If there is no good way of writing integers, print No
.
Otherwise, print lines. The -th line should contain the integer written on Vertex .
Any good way of writing integers will be accepted.
3 4
1 2 1
2 3 2
3 1 3
1 3 1
1
2
1
- We write , , and on Vertex , , and , respectively.
- Edge connects Vertex and , and its label is .- Only the integer written on Vertex equals the label, so this edge will not get removed.
- Only the integer written on Vertex equals the label, so this edge will not get removed.
- Edge connects Vertex and , and its label is .- Only the integer written on Vertex equals the label, so this edge will not be removed.
- Only the integer written on Vertex equals the label, so this edge will not be removed.
- Edge connects Vertex and , and its label is .- Both integers written on the vertices differ from the label, so this edge will be removed.
- Both integers written on the vertices differ from the label, so this edge will be removed.
- Edge connects Vertex and , and its label is .- Both integers written on the vertices equal the label, so this edge will be removed.
- Both integers written on the vertices equal the label, so this edge will be removed.
- After Edge and are removed, the graph will still be connected, so this is a good way of writing integers.