#C. ARC108C - Keep Graph Connected

    Type: Default 1000ms 512MiB

ARC108C - Keep Graph Connected

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 500 points

Problem Statement

Given is an undirected connected graph with N vertices numbered 1 to N, and M edges numbered 1 to M. The given graph may contain multi-edges but not self loops.

Each edge has an integer label between 1 and N (inclusive). Edge i has a label ci, and it connects Vertex ui and vi bidirectionally.

Snuke will write an integer between 1 and N (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 x and y be the integers written on the vertices that are the endpoints of the edge. Exactly one of x and y 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

  • 2N105
  • N1M2×105
  • 1ui,vi,ciN
  • The given graph is connected and has no self-loops.

Input

Input is given from Standard Input in the following format:

N M
u1 v1 c1

uM vM cM

Output

If there is no good way of writing integers, print No. Otherwise, print N lines. The i-th line should contain the integer written on Vertex i. Any good way of writing integers will be accepted.


Sample Input 1

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

Sample Output 1

1
2
1
  • We write 1, 2, and 1 on Vertex 1, 2, and 3, respectively.
  • Edge 1 connects Vertex 1 and 2, and its label is 1.
    • Only the integer written on Vertex 1 equals the label, so this edge will not get removed.
  • Edge 2 connects Vertex 2 and 3, and its label is 2.
    • Only the integer written on Vertex 2 equals the label, so this edge will not be removed.
  • Edge 3 connects Vertex 1 and 3, and its label is 3.
    • Both integers written on the vertices differ from the label, so this edge will be removed.
  • Edge 4 connects Vertex 1 and 3, and its label is 1.
    • Both integers written on the vertices equal the label, so this edge will be removed.
  • After Edge 3 and 4 are removed, the graph will still be connected, so this is a good way of writing integers.
</span>

军训训练赛1

Not Attended
Status
Done
Rule
IOI
Problem
7
Start at
2023-8-20 8:00
End at
2023-8-20 11:00
Duration
3 hour(s)
Host
Partic.
12