stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <vector>



#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

#define CLOSEALL() fclose(stdin), fclose(stdout)

#define eprintf(...) fprintf(stderr, ##__VA_ARGS__)



using namespace std;



const int MAXN = 1e5 + 10;



int u, v;

int N, M, Q;

vector <int> Adj[MAXN];

int color[MAXN];

int V[MAXN], D[MAXN], C[MAXN];



bool vist[MAXN][11];



void solve(int cur, int dep, int col)

{

	if(vist[cur][dep] || dep < 0)

		return;

	vist[cur][dep] = true;



	if(color[cur] == 0)

		color[cur] = col;



	for(vector<int>::iterator itr = Adj[cur].begin(); itr != Adj[cur].end(); ++itr)

		solve(*itr, dep - 1, col);

	solve(cur, dep-1, col);



}



int main()

{

	//REDIRECT("splatter");



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

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

		scanf("%d%d", &u, &v), Adj[u].push_back(v), Adj[v].push_back(u);



	scanf("%d", &Q);

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

		scanf("%d%d%d", &V[i], &D[i], &C[i]);

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

		solve(V[i], D[i], C[i]);



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

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



	CLOSEALL();

	return 0;

}


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

#include<cstring>

#include<algorithm>

#include<queue>

#include<vector>

using namespace std;



const int MAXN=1e5+5;



int n,m,Q;

int co[MAXN],last[MAXN];

int Ehead[MAXN],ecnt;

struct edge{

    int v,nxt;

}E[MAXN*2];

struct node{

    int pos,val,co;

}T[MAXN];



void addedge(int u,int v){

    E[++ecnt]=(edge){v,Ehead[u]};

    Ehead[u]=ecnt;

}



void dfs(int u,int dep,int co,int fa=0){

    if(dep<=last[u]) return;

    last[u]=dep;

    if(!::co[u]) ::co[u]=co;

    for(int i=Ehead[u];i;i=E[i].nxt){

        int v=E[i].v;

        if(v==fa) continue;

        dfs(v,dep-1,co,u);

    }

}



int main(){

    //freopen("splatter.in","r",stdin);

    //freopen("splatter.out","w",stdout);



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

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

        int u,v;

        scanf("%d%d",&u,&v);

        addedge(u,v);

        addedge(v,u);

    }

    memset(last,-1,sizeof last);

    scanf("%d",&Q);

    for(int i=1;i<=Q;i++) scanf("%d%d%d",&T[i].pos,&T[i].val,&T[i].co);

    for(int i=Q;i>=1;i--) dfs(T[i].pos,T[i].val,T[i].co);

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



    fclose(stdin);

    fclose(stdout);

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

#include <vector>



#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

#define CLOSEALL() fclose(stdin), fclose(stdout)

#define eprintf(...) fprintf(stderr, ##__VA_ARGS__)



using namespace std;



const int MAXN = 1e5 + 10;



int u, v;

int N, M, Q;

vector <int> Adj[MAXN];

int color[MAXN];

int V[MAXN], D[MAXN], C[MAXN];



bool vist[MAXN][11];



void solve(int cur, int dep, int col)

{

	if(vist[cur][dep] || dep < 0)

		return;

	vist[cur][dep] = true;



	if(color[cur] == 0)

		color[cur] = col;



	for(vector<int>::iterator itr = Adj[cur].begin(); itr != Adj[cur].end(); ++itr)

		solve(*itr, dep - 1, col);

	solve(cur, dep-1, col);



}



int main()

{

	//REDIRECT("splatter");



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

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

		scanf("%d%d", &u, &v), Adj[u].push_back(v), Adj[v].push_back(u);



	scanf("%d", &Q);

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

		scanf("%d%d%d", &V[i], &D[i], &C[i]);

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

		solve(V[i], D[i], C[i]);



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

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



	CLOSEALL();

	return 0;

}


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

using namespace std;

const int N = 1e5+20;

struct edge { int ver,next; } e[N<<1];

int n,m,q,t,Head[N],ans[N],v[N],d[N],c[N],dis[N];

inline void insert(int x,int y) { e[++t] = (edge){y,Head[x]} , Head[x] = t; }

inline void input(void)

{

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

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

    {

        int u,v;

        scanf("%d%d",&u,&v);

        insert( u , v );

        insert( v , u );

    }

    scanf("%d",&q);

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

        scanf("%d%d%d",&v[i],&d[i],&c[i]);

}

inline void dfs(int x,int d,int col)

{

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

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

    dis[x] = d;

    for (int i=Head[x];i;i=e[i].next)

    {

        int y = e[i].ver;

        dfs( y , d-1 , col );

    }

}

int main(void)

{

    input();

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

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

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

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

    return 0;

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

using namespace std;

const int Maxn=100005;

int n,m,q;

int vt[Maxn],d[Maxn],c[Maxn];

vector <int> g[Maxn];

int dp[Maxn],col[Maxn];

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

{

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

	if (dp[v]>=d || d==0) return;

	dp[v]=d;for (int i=0;i<g[v].size();++i)

		dfs(g[v][i],d-1,c);

}

int main()

{

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

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

	{

		int u,v;

		scanf("%d%d",&u,&v);

		g[u].push_back(v);

		g[v].push_back(u);

	}

	scanf("%d",&q);

	for (int i=0;i<q;++i) scanf("%d%d%d",vt+i,d+i,c+i);

	for (int i=q-1;i>=0;--i) dfs(vt[i],d[i],c[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.5481876874550244x):
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+20;

struct edge { int ver,next; } e[N<<1];

int n,m,q,t,Head[N],ans[N],v[N],d[N],c[N],dis[N];

inline void insert(int x,int y) { e[++t] = (edge){y,Head[x]} , Head[x] = t; }

inline void input(void)

{

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

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

    {

        int u,v;

        scanf("%d%d",&u,&v);

        insert( u , v );

        insert( v , u );

    }

    scanf("%d",&q);

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

        scanf("%d%d%d",&v[i],&d[i],&c[i]);

}

inline void dfs(int x,int d,int col)

{

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

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

    dis[x] = d;

    for (int i=Head[x];i;i=e[i].next)

    {

        int y = e[i].ver;

        dfs( y , d-1 , col );

    }

}

int main(void)

{

    input();

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

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

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

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

    return 0;

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

using namespace std;

int c[100005][11];

int col[100005];

vector<int> g[100005];

int main()

{

	int n,m,q;

	cin>>n>>m;

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

	{

		int a,b;

		cin>>a>>b;

		--a;

		--b;

		g[a].push_back(b);

		g[b].push_back(a);

	}

	cin>>q;

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

	{

		int v,d;

		cin>>v>>d>>col[i+1];

		--v;

		c[v][d]=i+1;

	}

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

	{

		for(int j=0;j<n;j++)

		{

			for(int k=0;k<g[j].size();k++)

			{

				c[g[j][k]][i]=max(c[j][i+1],c[g[j][k]][i]);

			}

		}

	}

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

	{

		int res=0;

		for(int j=0;j<11;j++)

		{

			res=max(c[i][j],res);

		}

		cout<<col[res]<<endl;

	}

	return 0;

}

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

using namespace std;

const int N = 1e5+20;

struct edge { int ver,next; } e[N<<1];

int n,m,q,t,Head[N],ans[N],v[N],d[N],c[N],dis[N];

inline void insert(int x,int y) { e[++t] = (edge){y,Head[x]} , Head[x] = t; }

inline void input(void)

{

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

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

    {

        int u,v;

        scanf("%d%d",&u,&v);

        insert( u , v );

        insert( v , u );

    }

    scanf("%d",&q);

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

        scanf("%d%d%d",&v[i],&d[i],&c[i]);

}

inline void dfs(int x,int d,int col)

{

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

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

    dis[x] = d;

    for (int i=Head[x];i;i=e[i].next)

    {

        int y = e[i].ver;

        dfs( y , d-1 , col );

    }

}

int main(void)

{

    input();

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

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

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

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

    return 0;

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

#include<iomanip>

#include<algorithm>

#include<cstring>

#include<string>

#include<cmath>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};

const long long llinf=9223372036854775807ll;

const int N=100005;

int a[N][3],ma[N],ans[N],bfs[N];

vector<int> g[N];

void go(int in[])

{

	int x=in[0]-1,dd=in[1],v=in[2];

	if(dd<ma[x])

		return ;

	ma[x]=dd;

	bfs[0]=x;

	int rr=1;

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

	{

		int x=bfs[i];

		if(!ans[x])

			ans[x]=v;

		if(!ma[x])

			continue;

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

		{

			int y=g[x][i];

			int nd=ma[x]-1;

			if(nd>ma[y])

			{

				ma[y]=nd;

				bfs[rr++]=y;

			}

		}

	}

}

int n,m,q,x,y;

int main(){

	cin>>n>>m;

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

	{

		cin>>x>>y;

		x--,y--;

		g[x].push_back(y);

		g[y].push_back(x);  

	}

	cin>>q;

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

		for(int j=0;j<3;j++)

			cin>>a[i][j];

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

		ma[i]=-1;

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

		go(a[i]);

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

		cout<<ans[i]<<'\n';

	return 0;

}

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

using namespace std;

const int N = 1e5+20;

struct edge { int ver,next; } e[N<<1];

int n,m,q,t,Head[N],ans[N],v[N],d[N],c[N],dis[N];

inline void insert(int x,int y) { e[++t] = (edge){y,Head[x]} , Head[x] = t; }

inline void input(void)

{

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

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

    {

        int u,v;

        scanf("%d%d",&u,&v);

        insert( u , v );

        insert( v , u );

    }

    scanf("%d",&q);

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

        scanf("%d%d%d",&v[i],&d[i],&c[i]);

}

inline void dfs(int x,int d,int col)

{

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

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

    dis[x] = d;

    for (int i=Head[x];i;i=e[i].next)

    {

        int y = e[i].ver;

        dfs( y , d-1 , col );

    }

}

int main(void)

{

    input();

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

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

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

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

    return 0;

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

#include<iomanip>

#include<algorithm>

#include<cstring>

#include<string>

#include<cmath>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};

const long long llinf=9223372036854775807ll;

const int N=100005;

int a[N][3],ma[N],ans[N],bfs[N];

vector<int> g[N];

void go(int in[])

{

	int x=in[0]-1,dd=in[1],v=in[2];

	if(dd<ma[x])

		return ;

	ma[x]=dd;

	bfs[0]=x;

	int rr=1;

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

	{

		int x=bfs[i];

		if(!ans[x])

			ans[x]=v;

		if(!ma[x])

			continue;

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

		{

			int y=g[x][i];

			int nd=ma[x]-1;

			if(nd>ma[y])

			{

				ma[y]=nd;

				bfs[rr++]=y;

			}

		}

	}

}

int n,m,q,x,y;

int main(){

	cin>>n>>m;

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

	{

		cin>>x>>y;

		x--,y--;

		g[x].push_back(y);

		g[y].push_back(x);  

	}

	cin>>q;

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

		for(int j=0;j<3;j++)

			cin>>a[i][j];

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

		ma[i]=-1;

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

		go(a[i]);

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

		cout<<ans[i]<<'\n';

	return 0;

}

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

using namespace std;

#define C getchar()

inline int read() {

	int num = 0;

	char c = C;

	for(;c<'0' || c>'9';c=C);

	for(;c>='0' && c<='9';c=C) num = (num << 1) + (num << 3) + (c ^ 48);

	return num;

}



//int nxt[200010],head[100010],to[200010],tot;

//

//inline void add(int x,int y) {

//	nxt[++tot] = head[x],head[x] = tot,to[tot] = y;

//}



int vis[100010][12];



vector<int> edge[100010];



inline void putc(int x,int d,int cl) {

	if (d == -1) return ;

	if (vis[x][d]) return ;

	vis[x][d] = cl;

	for(int i=0;i<edge[x].size();++i) putc(edge[x][i] , d - 1 , cl);

}



int n,m,Q;

struct node {

	int rt,d,cl;

}a[100010];



int main() {

//	freopen("1.in","r",stdin);

//	freopen("d.out","w",stdout);

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

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

		int u = read(),v = read();

		edge[u].push_back(v);

		edge[v].push_back(u);

//		add(u , v);add(v , u);

	}

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

  for(int i=1;i<=n;++i) edge[i].push_back(i);

	

	Q = read();

	for(int i=1;i<=Q;++i) a[i].rt = read(),a[i].d = read(),a[i].cl = read();

	for(int i=Q;i>=1;--i) putc(a[i].rt , a[i].d , a[i].cl);

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

	return 0;

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



using namespace std;

const int N = 2e5;



int n, q, m;

int vis[N][20], color[N], v[N], d[N], c[N];

vector < int > a[N];



int read(void)

{

	int s = 0, w = 0; char c = getchar();

	while (c < '0' || c > '9') w |= c == '-', c = getchar();

	while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar();

	return w ? -s : s;

}



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

{

	if (vis[v][d]) return;

	vis[v][d] = 1;

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

	if (d == 0) return;

	for (int i=0;i<a[v].size();++i)

	{

		int y = a[v][i];

		dfs(y,d-1,c);	

	} 

	return;

}



int main(void)

{

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

	for (int i=1,x,y;i<=m;++i)

	{

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

		a[x].push_back(y);

		a[y].push_back(x);

	}

	int q = read();

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

		v[i] = read();

		d[i] = read();

		c[i] = read();

	}

	while (q) dfs(v[q],d[q],c[q]), q --;

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

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

	return 0;

}

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

using namespace std;

#define C getchar()

inline int read() {

	int num = 0;

	char c = C;

	for(;c<'0' || c>'9';c=C);

	for(;c>='0' && c<='9';c=C) num = (num << 1) + (num << 3) + (c ^ 48);

	return num;

}



//int nxt[200010],head[100010],to[200010],tot;

//

//inline void add(int x,int y) {

//	nxt[++tot] = head[x],head[x] = tot,to[tot] = y;

//}



int vis[100010][12];



vector<int> edge[100010];



inline void putc(int x,int d,int cl) {

	if (d == -1) return ;

	if (vis[x][d]) return ;

	vis[x][d] = cl;

	for(int i=0;i<edge[x].size();++i) putc(edge[x][i] , d - 1 , cl);

}



int n,m,Q;

struct node {

	int rt,d,cl;

}a[100010];



int main() {

//	freopen("1.in","r",stdin);

//	freopen("d.out","w",stdout);

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

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

		int u = read(),v = read();

		edge[u].push_back(v);

		edge[v].push_back(u);

//		add(u , v);add(v , u);

	}

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

  for(int i=1;i<=n;++i) edge[i].push_back(i);

	

	Q = read();

	for(int i=1;i<=Q;++i) a[i].rt = read(),a[i].d = read(),a[i].cl = read();

	for(int i=Q;i>=1;--i) putc(a[i].rt , a[i].d , a[i].cl);

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

	return 0;

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

#include<iomanip>

#include<algorithm>

#include<cstring>

#include<string>

#include<cmath>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};

const long long llinf=9223372036854775807ll;

const int N=100005;

int a[N][3],ma[N],ans[N],bfs[N];

vector<int> g[N];

void go(int in[])

{

	int x=in[0]-1,dd=in[1],v=in[2];

	if(dd<ma[x])

		return ;

	ma[x]=dd;

	bfs[0]=x;

	int rr=1;

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

	{

		int x=bfs[i];

		if(!ans[x])

			ans[x]=v;

		if(!ma[x])

			continue;

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

		{

			int y=g[x][i];

			int nd=ma[x]-1;

			if(nd>ma[y])

			{

				ma[y]=nd;

				bfs[rr++]=y;

			}

		}

	}

}

int n,m,q,x,y;

int main(){

	cin>>n>>m;

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

	{

		cin>>x>>y;

		x--,y--;

		g[x].push_back(y);

		g[y].push_back(x);  

	}

	cin>>q;

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

		for(int j=0;j<3;j++)

			cin>>a[i][j];

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

		ma[i]=-1;

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

		go(a[i]);

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

		cout<<ans[i]<<'\n';

	return 0;

}

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

using namespace std;

int n,m,Q,u[100010],d[100010],t=0,c[100010],Link[100010],color[100010][15];

vector <int> edge[100010];

struct dsa

{

	int v,nex;

}e[200010];

void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;}

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

{

	if (dis==-1) return;

	if (color[now][dis]) return;

	color[now][dis]=col;

	for (int i=0;i<edge[now].size();i++) 

	  dfs(edge[now][i],dis-1,col);

}

int main()

{

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

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

		int xx,yy;

		scanf("%d%d",&xx,&yy);

		edge[xx].push_back(yy);

		edge[yy].push_back(xx);

	}

	scanf("%d",&Q);

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

	  scanf("%d%d%d",&u[i],&d[i],&c[i]);

	for (int i=1;i<=n;i++)	edge[i].push_back(i);

	for (int i=Q;i;i--)

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

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

	  printf("%d\n",color[i][0]);

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



using namespace std;

const int N = 2e5;



int n, q, m;

int vis[N][20], color[N], v[N], d[N], c[N];

vector < int > a[N];



int read(void)

{

	int s = 0, w = 0; char c = getchar();

	while (c < '0' || c > '9') w |= c == '-', c = getchar();

	while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar();

	return w ? -s : s;

}



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

{

	if (vis[v][d]) return;

	vis[v][d] = 1;

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

	if (d == 0) return;

	for (int i=0;i<a[v].size();++i)

	{

		int y = a[v][i];

		dfs(y,d-1,c);	

	} 

	return;

}



int main(void)

{

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

	for (int i=1,x,y;i<=m;++i)

	{

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

		a[x].push_back(y);

		a[y].push_back(x);

	}

	int q = read();

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

		v[i] = read();

		d[i] = read();

		c[i] = read();

	}

	while (q) dfs(v[q],d[q],c[q]), q --;

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

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

	return 0;

}

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

using namespace std;

int n,m,Q,u[100010],d[100010],t=0,c[100010],Link[100010],color[100010][15];

vector <int> edge[100010];

struct dsa

{

	int v,nex;

}e[200010];

void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;}

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

{

	if (dis==-1) return;

	if (color[now][dis]) return;

	color[now][dis]=col;

	for (int i=0;i<edge[now].size();i++) 

	  dfs(edge[now][i],dis-1,col);

}

int main()

{

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

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

		int xx,yy;

		scanf("%d%d",&xx,&yy);

		edge[xx].push_back(yy);

		edge[yy].push_back(xx);

	}

	scanf("%d",&Q);

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

	  scanf("%d%d%d",&u[i],&d[i],&c[i]);

	for (int i=1;i<=n;i++)	edge[i].push_back(i);

	for (int i=Q;i;i--)

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

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

	  printf("%d\n",color[i][0]);

}
// Slower C++ solution:
#pragma GCC optimize(2)

#include <bits/stdc++.h>

#define LL long long

#define pb push_back

#define mp make_pair

#define INF 0x3f3f3f3f

#define Inf 1000000000000000000LL

#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)

#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)

#define per(i,x,y) for(int (i)=(x);(i)>=(y);(i)--)

#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)

#define foreach(i,x) for(auto i:x)

using namespace std;

typedef pair<int,int>pii;

int n,m,q;

vector<int>G[100010];

int v[100010],d[100010],c[100010],col[100010];

int now;

int used[100010];

inline void read(int &x){

    int f=1;x=0;char s=getchar();

    while(s<'0'||s>'9'){s=getchar();}

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

}

inline void dfs(int x,int d){

	if(used[x]>=d)return;

	used[x]=d;

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

	foreach(to,G[x])if(d)dfs(to,d-1);

}

int main(){

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

	read(n),read(m);

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

		read(x),read(y);

		G[x].pb(y),G[y].pb(x);

	}

	read(q);

	rep(i,q)read(v[i]),read(d[i]),read(c[i]);

	for(int i=q;i;i--){

		now=c[i];

		dfs(v[i],d[i]);

		// rep(i,n)cout<<col[i]<<' ';

		// puts("");

	}

	rep(i,n)cout<<col[i]<<endl;

	return 0;

}

/*

7 7

1 2

1 3

1 4

4 5

5 6

5 7

2 3

2

6 1 1

1 2 2

*/

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

#define LL long long

#define pb push_back

#define mp make_pair

#define INF 0x3f3f3f3f

#define Inf 1000000000000000000LL

#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)

#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)

#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)

#define foreach(i,x) for(auto (i):(x))

using namespace std;

typedef pair<int,int>pii;

int n,m,q;

int c[100010][20];

int co[100010];

vector<int>G[100010];

int main(){

	cin>>n>>m;

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

		int x,y;

		cin>>x>>y;

		x--,y--;

		G[x].pb(y);

		G[y].pb(x);

	}

	cin>>q;

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

		int v,d;

		cin>>v>>d>>co[i+1];

		v--;

		c[v][d]=i+1;

	}

	for(int i=11-2;i>=0;i--)

		for(int v=0;v<n;v++)

			for(int u:G[v]){

				c[u][i]=max(c[u][i],c[v][i+1]);

			}

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

		int mx=0;

		for(int j=0;j<11;j++)mx=max(mx,c[i][j]);

		cout<<co[mx]<<endl;

	}

	return 0;

}
// Slower C++ solution:
#pragma GCC optimize(2)

#include <bits/stdc++.h>

#define LL long long

#define pb push_back

#define mp make_pair

#define INF 0x3f3f3f3f

#define Inf 1000000000000000000LL

#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)

#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)

#define per(i,x,y) for(int (i)=(x);(i)>=(y);(i)--)

#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)

#define foreach(i,x) for(auto i:x)

using namespace std;

typedef pair<int,int>pii;

int n,m,q;

vector<int>G[100010];

int v[100010],d[100010],c[100010],col[100010];

int now;

int used[100010];

inline void read(int &x){

    int f=1;x=0;char s=getchar();

    while(s<'0'||s>'9'){s=getchar();}

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

}

inline void dfs(int x,int d){

	if(used[x]>=d)return;

	used[x]=d;

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

	foreach(to,G[x])if(d)dfs(to,d-1);

}

int main(){

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

	read(n),read(m);

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

		read(x),read(y);

		G[x].pb(y),G[y].pb(x);

	}

	read(q);

	rep(i,q)read(v[i]),read(d[i]),read(c[i]);

	for(int i=q;i;i--){

		now=c[i];

		dfs(v[i],d[i]);

		// rep(i,n)cout<<col[i]<<' ';

		// puts("");

	}

	rep(i,n)cout<<col[i]<<endl;

	return 0;

}

/*

7 7

1 2

1 3

1 4

4 5

5 6

5 7

2 3

2

6 1 1

1 2 2

*/

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

#include <vector>

#include <algorithm>

#include <cstring>

#define LL long long

#define pb push_back

#define mp make_pair

#define INF 0x3f3f3f3f

#define Inf 1000000000000000000LL

#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)

#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)

#define per(i,x,y) for(int (i)=(x);(i)>=(y);(i)--)

#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)

#define foreach(i,x) for(auto i:x)

using namespace std;

typedef pair<int,int>pii;

int n,m,q;

vector<int>G[100010];

int v[100010],d[100010],c[100010],col[100010];

int now;

int used[100010];

inline void read(int &x){

    int f=1;x=0;char s=getchar();

    while(s<'0'||s>'9'){s=getchar();}

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

}

inline void dfs(int x,int d){

	if(used[x]>=d)return;

	used[x]=d;

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

	foreach(to,G[x])if(d)dfs(to,d-1);

}

int main(){

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

	read(n),read(m);

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

		read(x),read(y);

		G[x].pb(y),G[y].pb(x);

	}

	read(q);

	rep(i,q)read(v[i]),read(d[i]),read(c[i]);

	reverse(v+1,v+q+1);

	reverse(d+1,d+q+1);

	reverse(c+1,c+q+1);

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

		now=c[i];

		dfs(v[i],d[i]);

		// rep(i,n)cout<<col[i]<<' ';

		// puts("");

	}

	rep(i,n)cout<<col[i]<<endl;

	return 0;

}

/*

7 7

1 2

1 3

1 4

4 5

5 6

5 7

2 3

2

6 1 1

1 2 2

*/