stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/***********************

*  Date: 2018.11.28    *

*  Problem:            *

*  Author: xuziyuan    * 

***********************/



#include <bits/stdc++.h>



#define rt0 return 0

#define rep(i,n) for(int i=0;i<n;i++)

#define repn(i,n) for(int i=1;i<=n;i++)

#define replet(c) for(char c='a';c<='z';c++)

#define LL long long

#define pii pair <int,int>

#define pb push_back

#define fi first

#define se second

#define mpr make_pair

#define sqr(a) ((a)*(a))



using namespace std;



const LL MOD=1e9+7;



int n,m,q,appe[100010][20],coap[100010];//appe:appearance

vector <int> g[100010];



int main()

{

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

		scanf("%d%d",&x,&y);

		g[x].pb(y);

		g[y].pb(x);

	}

	cin>>q;

	repn(i,q)

	{

		int x,y;

		scanf("%d%d%d",&x,&y,&coap[i]);

		appe[x][y]=i;

	}

	for(int i=9;i>=0;i--)//算能不能覆盖appe[j][i]之前要先算出appe[p][i+1]会不会被覆盖，所以i要倒着循环 

	{

		repn(p,n)

		{

			rep(k,g[p].size())//i在这里代表可以控制的范围

			{

				int j=g[p][k];

				appe[j][i]=max(appe[j][i],appe[p][i+1]);/*远一条边距离就要加1，这里是看后者可不可以覆盖前者，

				可以说是一种dp，一个类似递归的过程，如果再之前的点把后者覆盖了，也会在前者上体现出来*/

			}	

		}	

	} 

	repn(i,n)

	{

		int lst=0;

		rep(j,11) lst=max(lst,appe[i][j]);

		cout<<coap[lst]<<endl;

	}

	rt0;

}

// Faster C++ solution for the same problem (measured speedup: 3.58995434119474x):
//#pragma GCC optimize(2)

//#pragma GCC optimize(3)

#include <bits/stdc++.h>

#define N 100005

#define int long long

//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)

using namespace std ;

//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;

inline int read ()

{

    char c = getchar () ; int x = 0 , f = 1 ;

    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }

    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }

    return x * f ;

}

int n , m , ver[N << 1] , nxt[N << 1] , hed[N] , tot , ans[N] , Dis[N] ;

struct as {

	int v , d , c ;

} a[N] ;

void add (int x , int y) { ver[++ tot] = y ; nxt[tot] = hed[x] ; hed[x] = tot ; }

void dfs (int x , int col , int dis)

{

	if (! ans[x]) ans[x] = col ;

	if (! dis || Dis[x] >= dis) return ;

	Dis[x] = dis ;

	for (int i = hed[x] ; i ; i = nxt[i])

	{

		int y = ver[i] ;

		dfs (y , col , dis - 1) ;

	}

}

signed main ()

{

	n = read () , m = read () ;

	for (int i = 1 , u , v ; i <= m ; u = read () , v = read () , add (u , v) , add (v , u) , i ++) ;

	int q = read () ;

	for (int i = 1 ; i <= q ; i ++) a[i].v = read () , a[i].d = read () , a[i].c = read () ;

	for (int i = q ; i >= 1 ; i --) dfs (a[i].v , a[i].c , a[i].d) ;

	for (int i = 1 ; i <= n ; i ++) printf ("%d\n" , ans[i]) ;

}

/*

7 7

1 2

1 3

1 4

4 5	

5 6

5 7

2 3

2

6 1 1

1 2 2

*/
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

const int maxn=100005,INF=0x3f3f3f3f,mod=1000000007;

struct QES{

	int v,d,c;

	QES(){}

	QES(int x,int y,int z){v=x;d=y;c=z;}

}qes[maxn];

int n,m,q,vis[maxn],col[maxn];

vi eg[maxn];

void dfs(QES nd){

	if(col[nd.v]==0) col[nd.v]=nd.c;

	if(nd.d==0) return;

	for(int i=0;i<eg[nd.v].size();i++){

		if(vis[eg[nd.v][i]]<nd.d-1){

			vis[eg[nd.v][i]]=nd.d-1;

			dfs(QES(eg[nd.v][i],nd.d-1,nd.c));

		}

	}

}

int main(){

	int t1,t2;

	scanf("%d%d",&n,&m);

	for(int i=0;i<m;i++){

		scanf("%d%d",&t1,&t2);

		eg[t1].push_back(t2);

		eg[t2].push_back(t1);

	}

	scanf("%d",&q);

	for(int i=0;i<q;i++) scanf("%d%d%d",&qes[i].v,&qes[i].d,&qes[i].c);

	memset(vis,-1,sizeof(vis));

	for(int i=q-1;i>=0;i--){

		if(vis[qes[i].v]<qes[i].d){

			vis[qes[i].v]=qes[i].d;

			dfs(qes[i]);

		}

	}

	for(int i=1;i<=n;i++) printf("%d\n",col[i]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.969338826631743x):
#include<bits/stdc++.h>//这题是倒着染色吧

using namespace std;



const int N = 1e5 + 10;

int n, m;

struct edge { int y, nxt; } e[N << 2];

int lin[N], len;

int ans[N][20];

struct QUE { int v, d, c; } q[N];



inline int read() {

	int s = 0, f = 1;

	char ch;

	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;

	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';

	return s * f;

}



inline void insert(int xx, int yy) {

	e[++len] = (edge) { yy, lin[xx] };

	lin[xx] = len;

}



inline void dfs(int v, int d, int c) {

	if(d == -1)	return ;

	if(ans[v][d])	return ;//因为是倒着染，所以不用再染一遍

	ans[v][d] = c;

	for(int i = lin[v]; i; i = e[i].nxt)	dfs(e[i].y, d - 1, c);

}



int main() {

	n = read(), m = read();

	for(int i = 1; i <= m; ++i) {

		int x = read(), y = read();

		insert(x, y);

		insert(y, x);

	}

	for(int i = 1; i <= n; ++i)	insert(i, i);

	int Q = read();

	for(int i = 1; i <= Q; ++i)	q[i].v = read(), q[i].d = read(), q[i].c = read();

	for(int i = Q; i >= 1; --i)	dfs(q[i].v, q[i].d, q[i].c);

	for(int i = 1; i <= n; ++i)	printf("%d\n", ans[i][0]);

	return 0;

}

//感谢ZJH大佬提供思路
// Slower C++ solution:
/***********************

*  Date: 2018.11.28    *

*  Problem:            *

*  Author: xuziyuan    * 

***********************/



#include <bits/stdc++.h>



#define rt0 return 0

#define rep(i,n) for(int i=0;i<n;i++)

#define repn(i,n) for(int i=1;i<=n;i++)

#define replet(c) for(char c='a';c<='z';c++)

#define LL long long

#define pii pair <int,int>

#define pb push_back

#define fi first

#define se second

#define mpr make_pair

#define sqr(a) ((a)*(a))



using namespace std;



const LL MOD=1e9+7;



int n,m,q,appe[100010][20],coap[100010];//appe:appearance

vector <int> g[100010];



int main()

{

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

		scanf("%d%d",&x,&y);

		g[x].pb(y);

		g[y].pb(x);

	}

	cin>>q;

	repn(i,q)

	{

		int x,y;

		scanf("%d%d%d",&x,&y,&coap[i]);

		appe[x][y]=i;

	}

	for(int i=9;i>=0;i--)//算能不能覆盖appe[j][i]之前要先算出appe[p][i+1]会不会被覆盖，所以i要倒着循环 

	{

		repn(p,n)

		{

			rep(k,g[p].size())//i在这里代表可以控制的范围

			{

				int j=g[p][k];

				appe[j][i]=max(appe[j][i],appe[p][i+1]);/*远一条边距离就要加1，这里是看后者可不可以覆盖前者，

				可以说是一种dp，一个类似递归的过程，如果再之前的点把后者覆盖了，也会在前者上体现出来*/

			}	

		}	

	} 

	repn(i,n)

	{

		int lst=0;

		rep(j,11) lst=max(lst,appe[i][j]);

		cout<<coap[lst]<<endl;

	}

	rt0;

}

// Faster C++ solution for the same problem (measured speedup: 3.5830926874447737x):
#include<bits/stdc++.h>//这题是倒着染色吧

using namespace std;



const int N = 1e5 + 10;

int n, m;

struct edge { int y, nxt; } e[N << 2];

int lin[N], len;

int ans[N][20];

struct QUE { int v, d, c; } q[N];



inline int read() {

	int s = 0, f = 1;

	char ch;

	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;

	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';

	return s * f;

}



inline void insert(int xx, int yy) {

	e[++len] = (edge) { yy, lin[xx] };

	lin[xx] = len;

}



inline void dfs(int v, int d, int c) {

	if(d == -1)	return ;

	if(ans[v][d])	return ;//因为是倒着染，所以不用再染一遍

	ans[v][d] = c;

	for(int i = lin[v]; i; i = e[i].nxt)	dfs(e[i].y, d - 1, c);

}



int main() {

	n = read(), m = read();

	for(int i = 1; i <= m; ++i) {

		int x = read(), y = read();

		insert(x, y);

		insert(y, x);

	}

	for(int i = 1; i <= n; ++i)	insert(i, i);

	int Q = read();

	for(int i = 1; i <= Q; ++i)	q[i].v = read(), q[i].d = read(), q[i].c = read();

	for(int i = Q; i >= 1; --i)	dfs(q[i].v, q[i].d, q[i].c);

	for(int i = 1; i <= n; ++i)	printf("%d\n", ans[i][0]);

	return 0;

}

//感谢ZJH大佬提供思路
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

const int maxn=100005,INF=0x3f3f3f3f,mod=1000000007;

struct QES{

	int v,d,c;

	QES(){}

	QES(int x,int y,int z){v=x;d=y;c=z;}

}qes[maxn];

int n,m,q,vis[maxn],col[maxn];

vi eg[maxn];

void dfs(QES nd){

	if(col[nd.v]==0) col[nd.v]=nd.c;

	if(nd.d==0) return;

	for(int i=0;i<eg[nd.v].size();i++){

		if(vis[eg[nd.v][i]]<nd.d-1){

			vis[eg[nd.v][i]]=nd.d-1;

			dfs(QES(eg[nd.v][i],nd.d-1,nd.c));

		}

	}

}

int main(){

	int t1,t2;

	scanf("%d%d",&n,&m);

	for(int i=0;i<m;i++){

		scanf("%d%d",&t1,&t2);

		eg[t1].push_back(t2);

		eg[t2].push_back(t1);

	}

	scanf("%d",&q);

	for(int i=0;i<q;i++) scanf("%d%d%d",&qes[i].v,&qes[i].d,&qes[i].c);

	memset(vis,-1,sizeof(vis));

	for(int i=q-1;i>=0;i--){

		if(vis[qes[i].v]<qes[i].d){

			vis[qes[i].v]=qes[i].d;

			dfs(qes[i]);

		}

	}

	for(int i=1;i<=n;i++) printf("%d\n",col[i]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.915013301785509x):
#include<bits/stdc++.h>

using namespace std;

const int Max=1e5;

int N,M,Q,Num=0,num=0,lin[Max+10]={},Col[Max+10]={},v[Max+10]={},d[Max+10]={},c[Max+10]={},q[Max+10]={},vis[Max+10][15]={};

struct kk{

	int Id,Next;

} e[Max*2+10]={};

inline void insert(int x,int y){

	e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;

}

inline void dfs(int x,int Dep,int col){

	if(!Col[x]) Col[x]=col;

	if(vis[x][Dep]||Dep<=0) return;

	for(int i=0;i<=Dep;i++) ++vis[x][i];

	for(int i=lin[x];i;i=e[i].Next)

	 dfs(e[i].Id,Dep-1,col);

}

int main(){

	scanf("%d%d",&N,&M);

	for(int i=1;i<=M;i++){

		int x,y; scanf("%d%d",&x,&y);

		insert(x,y); insert(y,x);

	}

	scanf("%d",&Q);

	for(int i=1;i<=Q;i++) scanf("%d%d%d",&v[i],&d[i],&c[i]);

	for(int i=Q;i>=1;--i) dfs(v[i],d[i],c[i]);

	for(int i=1;i<=N;i++) printf("%d\n",Col[i]);

	return 0;

}
// Slower C++ solution:
/***********************

*  Date: 2018.11.28    *

*  Problem:            *

*  Author: xuziyuan    * 

***********************/



#include <bits/stdc++.h>



#define rt0 return 0

#define rep(i,n) for(int i=0;i<n;i++)

#define repn(i,n) for(int i=1;i<=n;i++)

#define replet(c) for(char c='a';c<='z';c++)

#define LL long long

#define pii pair <int,int>

#define pb push_back

#define fi first

#define se second

#define mpr make_pair

#define sqr(a) ((a)*(a))



using namespace std;



const LL MOD=1e9+7;



int n,m,q,appe[100010][20],coap[100010];//appe:appearance

vector <int> g[100010];



int main()

{

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

		scanf("%d%d",&x,&y);

		g[x].pb(y);

		g[y].pb(x);

	}

	cin>>q;

	repn(i,q)

	{

		int x,y;

		scanf("%d%d%d",&x,&y,&coap[i]);

		appe[x][y]=i;

	}

	for(int i=9;i>=0;i--)//算能不能覆盖appe[j][i]之前要先算出appe[p][i+1]会不会被覆盖，所以i要倒着循环 

	{

		repn(p,n)

		{

			rep(k,g[p].size())//i在这里代表可以控制的范围

			{

				int j=g[p][k];

				appe[j][i]=max(appe[j][i],appe[p][i+1]);/*远一条边距离就要加1，这里是看后者可不可以覆盖前者，

				可以说是一种dp，一个类似递归的过程，如果再之前的点把后者覆盖了，也会在前者上体现出来*/

			}	

		}	

	} 

	repn(i,n)

	{

		int lst=0;

		rep(j,11) lst=max(lst,appe[i][j]);

		cout<<coap[lst]<<endl;

	}

	rt0;

}

// Faster C++ solution for the same problem (measured speedup: 3.534053439519618x):
#include<bits/stdc++.h>

using namespace std;

const int Max=1e5;

int N,M,Q,Num=0,num=0,lin[Max+10]={},Col[Max+10]={},v[Max+10]={},d[Max+10]={},c[Max+10]={},q[Max+10]={},vis[Max+10][15]={};

struct kk{

	int Id,Next;

} e[Max*2+10]={};

inline void insert(int x,int y){

	e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;

}

inline void dfs(int x,int Dep,int col){

	if(!Col[x]) Col[x]=col;

	if(vis[x][Dep]||Dep<=0) return;

	for(int i=0;i<=Dep;i++) ++vis[x][i];

	for(int i=lin[x];i;i=e[i].Next)

	 dfs(e[i].Id,Dep-1,col);

}

int main(){

	scanf("%d%d",&N,&M);

	for(int i=1;i<=M;i++){

		int x,y; scanf("%d%d",&x,&y);

		insert(x,y); insert(y,x);

	}

	scanf("%d",&Q);

	for(int i=1;i<=Q;i++) scanf("%d%d%d",&v[i],&d[i],&c[i]);

	for(int i=Q;i>=1;--i) dfs(v[i],d[i],c[i]);

	for(int i=1;i<=N;i++) printf("%d\n",Col[i]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int n,m,q;

vector <int> g[100004];

int juv[100004];

int col[100004],qu;

void bfs(int s1,int d1,int c1){

	queue <pair<int,int> > q;

	q.push(make_pair(s1,0)); 

	while (!q.empty()){

		pair<int,int> x=q.front();

		q.pop();

		if (x.second!=d1 && d1-x.second<=juv[x.first]) continue;

		else juv[x.first]=d1-x.second;

		if (col[x.first]>0);

		else col[x.first]=c1;

		if (x.second>=d1) continue;

		else for (int i=0;i<g[x.first].size();i++)

			q.push(make_pair(g[x.first][i],x.second+1));  

	}

}

int s[100004],d[100004],c[100004];

int main(){

	memset (col,0,sizeof(col)); 

	cin>>n>>m;

	for (int i=0;i<m;i++){

		int x,y;

		cin>>x>>y;

		g[x].push_back(y);

		g[y].push_back(x);

	}

	cin>>q;

	for (int i=0;i<q;i++) cin>>s[i]>>d[i]>>c[i];

	reverse (s,s+q);

	reverse (d,d+q);

	reverse (c,c+q);

	for (int i=0;i<q;i++) bfs (s[i],d[i],c[i]);

	for (int i=1;i<=n;i++) cout<<col[i]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.9777829879811413x):
#include<bits/stdc++.h>

#define N 100005

using namespace std;

int n,m,cnt,tot,fst[N],pnt[N<<1],nxt[N<<1],ans[N],dp[N][11];

void add(int x,int y){

	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;

}

int main(){

	scanf("%d%d",&n,&m);

	int i,j,x,y;

	for (i=1; i<=m; i++){

		scanf("%d%d",&x,&y);

		add(x,y); add(y,x);

	}

	scanf("%d",&cnt);

	for (i=1; i<=cnt; i++){

		scanf("%d%d%d",&x,&y,&ans[i]); dp[x][y]=i;

	}

	for (i=9; i>=0; i--)

		for (x=1; x<=n; x++){

			dp[x][i]=max(dp[x][i],dp[x][i+1]);

			for (j=fst[x]; j; j=nxt[j]) dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);

		}

	for (i=1; i<=n; i++) printf("%d\n",ans[dp[i][0]]);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define mp make_pair

#define pb push_back

typedef long long ll;

typedef long double ld;

using namespace std;

int cl[120000],lst[120000];

vector<int> eds[120000];

int n,m,q,a,b,v,d,c;

void dfs1(int v,int d,int c)

{

	if (!cl[v]) cl[v]=c;

	if (lst[v]>=d) return;

	lst[v]=d;

	if (d==0) return;

	for (int u: eds[v]) dfs1(u, d - 1, c);

}

vector<tuple<int, int, int >> vv;

int main()

{

	cin>>n>>m;

	for (int i=0;i<m;i++)

	{

		cin>>a>>b;

		--a, --b;

		eds[a].pb(b);

		eds[b].pb(a);

	}

	cin>>q;

	for (int i=0;i<q;i++)

	{

		cin>>v>>d>>c;

		--v;

		vv.pb(make_tuple(v, d, c));

	}

	reverse(vv.begin(),vv.end());

	for (int i=0;i<q;i++)

	{

		int v, d, c;

		tie(v, d, c) = vv[i];

		dfs1(v, d, c);

	}

	for (int i=0;i<n;i++) cout<<cl[i]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.068882177279514x):
#include<bits/stdc++.h>

#define N 100005

using namespace std;

int n,m,cnt,tot,fst[N],pnt[N<<1],nxt[N<<1],ans[N],dp[N][11];

void add(int x,int y){

	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;

}

int main(){

	scanf("%d%d",&n,&m);

	int i,j,x,y;

	for (i=1; i<=m; i++){

		scanf("%d%d",&x,&y);

		add(x,y); add(y,x);

	}

	scanf("%d",&cnt);

	for (i=1; i<=cnt; i++){

		scanf("%d%d%d",&x,&y,&ans[i]); dp[x][y]=i;

	}

	for (i=9; i>=0; i--)

		for (x=1; x<=n; x++){

			dp[x][i]=max(dp[x][i],dp[x][i+1]);

			for (j=fst[x]; j; j=nxt[j]) dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);

		}

	for (i=1; i<=n; i++) printf("%d\n",ans[dp[i][0]]);

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;

int N,M,Q;

vector <int> g[100004];

int col[100004],turns[100004];

bool vis[100004];

void bfs(int v,int d,int c){

	memset (vis,0,sizeof(vis));

	queue <pii> q;

	q.push(pii(v,0));

	while (!q.empty()){

		int x=q.front().first,dist=q.front().second;

		q.pop();

		if (d-dist<=turns[x]) continue;

		turns[x]=d-dist; 

		if (dist>d) continue;

		if (vis[x]) continue;

		vis[x]=1;

		if (col[x]==0) col[x]=c;

		for (int i=0;i<g[x].size();i++)

			q.push(pii(g[x][i],dist+1)); 

	}

}

int v[100004],d[100004],c[100004];

int main(){

	memset (col,0,sizeof(col));

	memset (turns,-1,sizeof(turns));

	cin>>N>>M;

	for (int i=0;i<M;i++){

		int x,y;

		cin>>x>>y;

		g[x].push_back(y);

		g[y].push_back(x);

	}

	cin>>Q;

	for (int i=0;i<Q;i++){

		cin>>v[i]>>d[i]>>c[i];

	}

	for (int i=Q-1;i>=0;i--)

		bfs(v[i],d[i],c[i]);

	for (int i=1;i<=N;i++)

		cout<<col[i]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1590025002451514x):
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

int n,m,q;

vector <int> g[100004];

int juv[100004];

int col[100004],qu;

void bfs(int s1,int d1,int c1){

	queue <pair<int,int> > q;

	q.push(make_pair(s1,0)); 

	while (!q.empty()){

		pair<int,int> x=q.front();

		q.pop();

		if (x.second!=d1 && d1-x.second<=juv[x.first]) continue;

		else juv[x.first]=d1-x.second;

		if (col[x.first]>0);

		else col[x.first]=c1;

		if (x.second>=d1) continue;

		else for (int i=0;i<g[x.first].size();i++)

			q.push(make_pair(g[x.first][i],x.second+1));  

	}

}

int s[100004],d[100004],c[100004];

int main(){

	memset (col,0,sizeof(col)); 

	cin>>n>>m;

	for (int i=0;i<m;i++){

		int x,y;

		cin>>x>>y;

		g[x].push_back(y);

		g[y].push_back(x);  

	}

	cin>>q;

	for (int i=0;i<q;i++)

		cin>>s[i]>>d[i]>>c[i];

	reverse (s,s+q);

	reverse (d,d+q);

	reverse (c,c+q);

	for (int i=0;i<q;i++)

		bfs (s[i],d[i],c[i]);

	for (int i=1;i<=n;i++)

		cout<<col[i]<<endl;

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;

int N,M,Q;

vector <int> g[100004];

int col[100004],turns[100004];

bool vis[100004];

void bfs(int v,int d,int c){

	memset (vis,0,sizeof(vis));

	queue <pii> q;

	q.push(pii(v,0));

	while (!q.empty()){

		int x=q.front().first,dist=q.front().second;

		q.pop();

		if (d-dist<=turns[x]) continue;

		turns[x]=d-dist; 

		if (dist>d) continue;

		if (vis[x]) continue;

		vis[x]=1;

		if (col[x]==0) col[x]=c;

		for (int i=0;i<g[x].size();i++)

			q.push(pii(g[x][i],dist+1)); 

	}

}

int v[100004],d[100004],c[100004];

int main(){

	memset (col,0,sizeof(col));

	memset (turns,-1,sizeof(turns));

	cin>>N>>M;

	for (int i=0;i<M;i++){

		int x,y;

		cin>>x>>y;

		g[x].push_back(y);

		g[y].push_back(x);

	}

	cin>>Q;

	for (int i=0;i<Q;i++){

		cin>>v[i]>>d[i]>>c[i];

	}

	for (int i=Q-1;i>=0;i--)

		bfs(v[i],d[i],c[i]);

	for (int i=1;i<=N;i++)

		cout<<col[i]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.544950293149081x):
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

int n,m,cnt,tot,fst[100004],pnt[100004<<1],nxt[100004<<1],ans[100004],dp[100004][12];

void add(int x,int y){

	pnt[++tot]=y;

	nxt[tot]=fst[x];

	fst[x]=tot;

}

int main(){

	cin>>n>>m;

	int i,j,x,y;

	for (i=1;i<=m;i++){

		cin>>x>>y;

		add(x,y);

		add(y,x);

	}

	cin>>cnt;

	for (i=1;i<=cnt;i++){

		cin>>x>>y>>ans[i];

		dp[x][y]=i;

	}

	for (i=9;i>=0;i--)

		for (x=1;x<=n;x++){

			dp[x][i]=max(dp[x][i],dp[x][i+1]);

			for (j=fst[x];j;j=nxt[j])

				dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);

			}

	for (i=1;i<=n;i++) cout<<ans[dp[i][0]]<<endl;

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

int n,m,q;

vector <int> g[100004];

int juv[100004];

int col[100004],qu;

void bfs(int s1,int d1,int c1){

	queue <pair<int,int> > q;

	q.push(make_pair(s1,0)); 

	while (!q.empty()){

		pair<int,int> x=q.front();

		q.pop();

		if (x.second!=d1 && d1-x.second<=juv[x.first]) continue;

		else juv[x.first]=d1-x.second;

		if (col[x.first]>0);

		else col[x.first]=c1;

		if (x.second>=d1) continue;

		else for (int i=0;i<g[x.first].size();i++)

			q.push(make_pair(g[x.first][i],x.second+1));  

	}

}

int s[100004],d[100004],c[100004];

int main(){

	memset (col,0,sizeof(col)); 

	cin>>n>>m;

	for (int i=0;i<m;i++){

		int x,y;

		cin>>x>>y;

		g[x].push_back(y);

		g[y].push_back(x);  

	}

	cin>>q;

	for (int i=0;i<q;i++)

		cin>>s[i]>>d[i]>>c[i];

	reverse (s,s+q);

	reverse (d,d+q);

	reverse (c,c+q);

	for (int i=0;i<q;i++)

		bfs (s[i],d[i],c[i]);

	for (int i=1;i<=n;i++)

		cout<<col[i]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.9214326907730883x):
#include <algorithm>

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bits/stdc++.h>

using namespace std;

int n,m,cnt,tot,fst[100004],pnt[100004<<1],nxt[100004<<1],ans[100004],dp[100004][12];

void add(int x,int y){

	pnt[++tot]=y;

	nxt[tot]=fst[x];

	fst[x]=tot;

}

int main(){

	cin>>n>>m;

	int i,j,x,y;

	for (i=1;i<=m;i++){

		cin>>x>>y;

		add(x,y);

		add(y,x);

	}

	cin>>cnt;

	for (i=1;i<=cnt;i++){

		cin>>x>>y>>ans[i];

		dp[x][y]=i;

	}

	for (i=9;i>=0;i--)

		for (x=1;x<=n;x++){

			dp[x][i]=max(dp[x][i],dp[x][i+1]);

			for (j=fst[x];j;j=nxt[j])

				dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);

			}

	for (i=1;i<=n;i++) cout<<ans[dp[i][0]]<<endl;

	return 0;

}