Professional Documents
Culture Documents
Update Colors - PrepBytes
Update Colors - PrepBytes
Update Colors - PrepBytes
You are given a simple undirected graph of N vertices and M edges. The ith edge connects two vertices ai
and bi .
Initially, all the vertices are painted with colour 0. You are supposed to perform Q operations on this graph.
In the ith operation you will be given three integers vi , di and ci . You have to repaint all the vertices having
distance less or equal to di from vertex vi in color ci .
Input Format
The first line contains two space-separated integers N and M , number of nodes and number of edges.
The Next M line contains two space separated integers, ith of which represent an edge between ai and bi .
Next Q lines contains three space separated integers, ith line is vi , di and ci .
Output Format
Print N lines. In the ith line, print the colour of vertex i after all the operations.
Time Limit
2 seconds
Constraints
1 ≤ N, M, Q ≤ 105
1 ≤ ai , b i , v i ≤ N
ai ≠ b i
0 ≤ di ≤ 10
1 ≤ ci ≤ 105
Example
Sample Input 1
7 6
1 2
1 3
3 6
4 5
5 7
2 4
5 1 1
228
Sample Output 1
1
Sample test case explanation
Initially all the nodes are painted in color 0.
[0, 0, 0, 0, 0, 0, 0]
1st operation: All the vertices having distance less than equal to 1 from vertex 5 are [4, 5, 7] will be painted
in color 1.
[0, 0, 0, 1, 1, 0, 1]
2nd operation: All the vertices having distance less than equal to 2 from vertex 2 are [1, 2, 3, 4, 5] will be
painted in color 8.
[8, 8, 8, 8, 8, 0, 1]