stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
//#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

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):
/***********************

*  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;

}

// Optimized solution to the same problem (faster):
//#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

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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,mindist[100004],col[100004],s[100004],d[100004],c[100004];

vector <int> g[100004];

void dfs(int x,int dist,int color){

	if (dist<=mindist[x]) return;

	mindist[x]=dist;

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

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

		dfs(g[x][i],dist-1,color);

}

int main(){

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

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

	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];

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

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

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

		cout<<col[i]<<"\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//************************

//*  Date: 2018.10.22    *

//*  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;

vector <int> g[100010];

int colo[100010],most[100010];

vector <pair<pii,int> > pa;

bool vis[100010];



int main()

{

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

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

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

		g[x].pb(y);

		g[y].pb(x);

	}

	cin>>q;

	rep(i,q)

	{

		int x,y,z;

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

		pa.pb({{x,y},z});

	}

	for(int i=pa.size()-1;i>=0;i--)

	{

		int x=pa[i].fi.fi,y=pa[i].fi.se,z=pa[i].se;

		queue <pii> q;

		q.push({x,0});

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

		while(!q.empty())

		{

			int pos=q.front().fi,all=q.front().se;

			q.pop();

			if(y-all<=most[pos]) continue;

			most[pos]=y-all;

			if(all>y) continue;

			if(vis[pos]) continue;

			//if(x==1) cout<<pos<<endl;

			vis[pos]=true;

			if(colo[pos]==0) colo[pos]=z;

			rep(i,g[pos].size()) q.push({g[pos][i],all+1});

		}

	}

	repn(i,n) printf("%d\n",colo[i]);

	rt0;

}

// Optimized solution to the same problem (faster):
/***********************

*  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],len=0;//appe:appearance

int list_top[200010],val[200010],nxt[200010];



void add(int x,int y)

{

	val[++len]=y;

	nxt[len]=list_top[x];

	list_top[x]=len;

}



int main()

{

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

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

		add(x,y);

		add(y,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)

		{

			for(int k=list_top[p];k!=0;k=nxt[k])//i在这里代表可以控制的范围

			{

				int j=val[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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/***********************

*  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,co[100010],most[100010];

vector <int> g[100010];

vector <pair<int,pii> > qs;

bool vis[100010];



int main()

{

	cin>>n>>m;

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

	rep(i,m)

	{

		int x,y;

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

		g[x].pb(y);

		g[y].pb(x);

	}

	cin>>q;

	rep(i,q)

	{

		int x,y,z;

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

		qs.pb({x,{y,z}});

	}

	for(int i=qs.size()-1;i>=0;i--)

	{

		//cout<<qs[i].fi<<' '<<qs[i].se.fi<<' '<<qs[i].se.se<<endl;

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

		int v=qs[i].fi,colo=qs[i].se.se,dist=qs[i].se.fi;

		queue <pii> q;

		q.push({v,0});

		while(!q.empty())

		{

			int pos=q.front().fi,dist1=q.front().se;

			//cout<<pos<<' '<<colo<<' '<<dist<<' '<<dist1<<endl;

			q.pop();

			if(most[pos]>=dist-dist1) continue;

			most[pos]=dist-dist1;

			if(vis[pos]) continue;

			vis[pos]=true;

			if(co[pos]==0) co[pos]=colo;

			if(dist1==dist) continue;

			rep(j,g[pos].size()) q.push({g[pos][j],dist1+1});

		}

	}

	repn(i,n) printf("%d\n",co[i]);

	rt0;

}

// Optimized solution to the same problem (faster):
/***********************

*  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],len=0;//appe:appearance

int list_top[200010],val[200010],nxt[200010];



void add(int x,int y)

{

	val[++len]=y;

	nxt[len]=list_top[x];

	list_top[x]=len;

}



int main()

{

	cin>>n>>m;

	rep(i,m)

	{

		int x,y;

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

		add(x,y);

		add(y,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)

		{

			for(int k=list_top[p];k!=0;k=nxt[k])//i在这里代表可以控制的范围

			{

				int j=val[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;

}

// Fastest known solution for this problem: