atcoder#AGC012B. [AGC012B] Splatter Painting

[AGC012B] Splatter Painting

Score : 700700 points

Problem Statement

Squid loves painting vertices in graphs.

There is a simple undirected graph consisting of NN vertices numbered 11 through NN, and MM edges. Initially, all the vertices are painted in color 00. The ii-th edge bidirectionally connects two vertices aia_i and bib_i. The length of every edge is 11.

Squid performed QQ operations on this graph. In the ii-th operation, he repaints all the vertices within a distance of did_i from vertex viv_i, in color cic_i.

Find the color of each vertex after the QQ operations.

Constraints

  • 1N,M,Q1051 \leq N,M,Q \leq 10^5
  • 1ai,bi,viN1 \leq a_i,b_i,v_i \leq N
  • aibia_i \neq b_i
  • 0di100 \leq d_i \leq 10
  • 1ci1051 \leq c_i \leq 10^5
  • did_i and cic_i are all integers.
  • There are no self-loops or multiple edges in the given graph.

Partial Score

  • 200200 points will be awarded for passing the testset satisfying 1N,M,Q2,0001 \leq N,M,Q \leq 2{,}000.

Input

Input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

::

aMa_{M} bMb_{M}

QQ

v1v_1 d1d_1 c1c_1

::

vQv_{Q} dQd_{Q} cQc_{Q}

Output

Print the answer in NN lines. In the ii-th line, print the color of vertex ii after the QQ operations.

7 7
1 2
1 3
1 4
4 5
5 6
5 7
2 3
2
6 1 1
1 2 2
2
2
2
2
2
1
0

Initially, each vertex is painted in color 00. In the first operation, vertices 55 and 66 are repainted in color 11. In the second operation, vertices 11, 22, 33, 44 and 55 are repainted in color 22.

2ab7e180230b159d42d35ea7e555b3b0.png

14 10
1 4
5 7
7 11
4 10
14 7
14 3
6 14
8 11
5 13
8 3
8
8 6 2
9 7 85
6 9 3
6 7 5
10 3 1
12 9 4
9 6 6
8 2 3
1
0
3
1
5
5
3
3
6
1
3
4
5
3

The given graph may not be connected.