stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int>q[200000];

int color[200000];

int flag[200000];

int n,m;

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

void dfs(int x,int cnt,int c)

{

   if(!color[x])

       color[x]=c;

   if(flag[x]>=cnt)

       return;

   if(cnt==0)

       return;

   flag[x]=cnt;

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

       dfs(q[x][i],cnt-1,c);

}

int main()

{

    cin>>n>>m;

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

    {

        int x,y;

        cin>>x>>y;

        q[x].push_back(y);

        q[y].push_back(x);

    }

    int q;

    cin>>q;

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

       cin>>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++)

        cout<<color[i]<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.553294471887914x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

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

#include<algorithm>

#include<cstring>

#define maxn 200050

#define add(u,v) (to[++top]=head[u],head[u]=top,w[top]=v)

#define For(x) for(int h=head[x],o=w[h];h;o=w[h=to[h]])

using namespace std;

int n,m,to[maxn],head[maxn],w[maxn],u,v,top;

int a[maxn],b[maxn],c[maxn],co[maxn],r[maxn],q,i;

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

{

	if (rg<=r[x]||rg<=0) return;

	r[x]=rg; 

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

	For(x) dfs(o,rg-1,col);

}

int main()

{

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

	while (m--)

	{

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

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

    }

    scanf("%d",&q);

    for (i=1;i<=q;i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);

    memset(co,0,sizeof(co)); memset(r,0,sizeof(r));

    for (i=q;i>=1;i--) dfs(a[i],b[i]+1,c[i]);

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8175445593592139x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

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

#include<iostream>

#include<queue>

#include<cstring>

#define N 100010

using namespace std;

struct Dis{

	int x,z;

};

queue<Dis>Q;

int a[N],c[N],d[N],e[N],f[N],num,h[N],n,m,p,q,t,col;

bool bo[N];

struct Edge{

	int p,q,n;

}b[N*2];

void ljb(int p,int q){

	b[++num].n=h[p];

	h[p]=num;

	b[num].p=p;

	b[num].q=q;

}

void Bfs(){

	int x,y,z;

	while(!Q.empty()){

		x=Q.front().x; z=Q.front().z; Q.pop(); 

//		printf("%d %d\n",x,z);

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

		e[x]=max(e[x],z);

		if(z==0)continue;

		for(int i=h[x];i!=0;i=b[i].n){

			y=b[i].q;

			if(e[y]<z-1)Q.push((Dis){y,z-1});

		}

	}

}

int main(){

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

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

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

		scanf("%d%d",&p,&q);

		ljb(p,q);

		ljb(q,p);

	}

	scanf("%d",&t);

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

	for(int i=t;i>=1;i--){

		if(e[a[i]]>=d[i])continue;

		col=c[i];

		Q.push((Dis){a[i],d[i]});

		Bfs();

	}

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

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

}

// Faster C++ solution for the same problem (measured speedup: 1.4236828584325414x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

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

#include<cstdio>

#include<cstring>

using namespace std;

int q[101000],H=0,T=0;

int col[101000],d[101000];

int h[101000],nxt[201000],to[201000],K=0;

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

void ins(int u,int v){nxt[++K]=h[u];h[u]=K;to[K]=v;}

int main()

{

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

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

	{

		int a,b;scanf("%d%d",&a,&b);

		ins(a,b);ins(b,a);

	}

	int Q;scanf("%d",&Q);

	for(int i=1;i<=Q;i++)scanf("%d%d%d",&V[i],&D[i],&C[i]);

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

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

	{

		if(D[i]>d[V[i]])

		{

			H=T=0;d[V[i]]=D[i];q[T++]=V[i];

			while(H<T)

			{

				int x=q[H++];if(!col[x])col[x]=C[i];

				for(int j=h[x];j;j=nxt[j])

				{

					if(d[to[j]]<d[x]-1)

					{

						d[to[j]]=d[x]-1;

						q[T++]=to[j];

					}

				}

			}

		}

	}

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

 } 

// Faster C++ solution for the same problem (measured speedup: 1.4227619221330972x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

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

#include<cmath>

#include<math.h>

#include<ctype.h>

#include<algorithm>

#include<string.h>

#include<stdio.h>

#include<iostream>

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

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

#define pb push_back

#define ms(a) memset((a),0,sizeof(a))

#define ll long long

#define vi vector<int>

#define mp make_pair

#define die assert(fasle)

#define pii pair<int,int>

#define INF 0x3f3f3f3f

#define N (int)1e5+5

using namespace std;

int n, m, q;

vi g[N];

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

int ans[N];

int lft;

int mds[N];

void dfs(int vv, int dd, int cc) {

	if (!lft) return;

	if (dd < 0) return;

	if (!ans[vv])ans[vv] = cc;

	if (dd <= mds[vv]) return;

	mds[vv] = dd;

	//printf("%d %d %d\n", vv, dd, cc);

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

		if (!g[vv][i])lft --;

		dfs(g[vv][i], dd-1, cc);

	}

}

int main() {

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

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

		int x, y;

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

		g[x].pb(y);

		g[y].pb(x);

	}

	scanf("%d", &q);

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

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

	}

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

		mds[i] = -1;

	}

	lft = n;

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

		//puts("");

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

//		for (int j = 1; j <= n; j ++) {

//			printf("%d ", ans[j]);

//		}

//		puts("");

//		printf("%d\n", lft);

//		puts("");

		if (!lft) break;

	}

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

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

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.570213049889292x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

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

#include <vector>

#include <cstring>

#define N 100005

using namespace std;

int n, m, a, b, q, v[N], d[N], c[N], ans[N], memo[N];

vector<int> g[N];



void f(int p, int q, int r) {

	if(q<0 || q<=memo[p]) return;

	memo[p] = q;

	if(!ans[p]) ans[p] = r;

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

		f(g[p][i], q-1, r);

	}

}



int main() {

	int i;

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

	while(m--) {

		scanf("%d%d", &a, &b);

		g[a].push_back(b);

		g[b].push_back(a);

	}

	scanf("%d", &q);

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

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

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

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

	}

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

	return 0;

}

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

#include <cstdio>

#define N 100005

using namespace std;

int n, m, a[N], b[N], q, v, d, c[N], x[15][N];



int main() {

	int i, j;

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

	for(i=1; i<=m; i++) scanf("%d%d", a+i, b+i);

	scanf("%d", &q);

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

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

		x[d][v] = i;

	}

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

		for(j=1; j<=n; j++) x[i][j] = max(x[i][j], x[i+1][j]);

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

			x[i][a[j]] = max(x[i][a[j]], x[i+1][b[j]]);

			x[i][b[j]] = max(x[i][b[j]], x[i+1][a[j]]);

		}

	}

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

	return 0;

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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



vector<int> E[100001];

int kotae[100001];

int Vis[100001];

void sagasu(int P, int D, int C) {

	if (D == 0 && kotae[P] == 0) kotae[P] = C;

	else if (Vis[P] < D) {

		Vis[P] = D;

		if (kotae[P] == 0) kotae[P] = C;

		for (int p : E[P]) {

			sagasu(p, D - 1, C);

		}

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M, Q;

	cin >> N >> M;

	rep(i, M) {

		int a, b;

		cin >> a >> b;

		E[a].pb(b);

		E[b].pb(a);

	}

	cin >> Q;

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

	rep(i, Q) cin >> v[i] >> d[i] >> c[i];



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

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

	}

	rep1(i, N) {

		co(kotae[i]);

	}



	Would you please return 0;

}

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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



pair<int, int> E[200001];

int H[200001];

int kotae[100001];

int Vis[100001];

void sagasu(int P, int D, int C) {

	if (D == 0 && kotae[P] == 0) kotae[P] = C;

	else if (Vis[P] < D) {

		Vis[P] = D;

		if (kotae[P] == 0) kotae[P] = C;

		for (int p = H[P]; p; p = E[p].second) {

			sagasu(E[p].first, D - 1, C);

		}

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M, Q;

	cin >> N >> M;

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

		int a, b;

		cin >> a >> b;

		E[i] = mp(a, H[b]);

		H[b] = i;

		E[i + 1] = mp(b, H[a]);

		H[a] = i + 1;

	}

	cin >> Q;

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

	rep(i, Q) cin >> v[i] >> d[i] >> c[i];



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

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

	}

	rep1(i, N) {

		co(kotae[i]);

	}



	Would you please return 0;

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

using namespace std;

typedef long long LL;

const int maxn = 100000+10;

int color[maxn][15];

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

vector <int> node[maxn];

void paint(int v1, int d1, int c1)

{    

    if(d1==-1)  return;    

	if(color[v1][d1] ) return;    

	color[v1][d1] = c1;    

	for(int i =0;i<node[v1].size();i++)        

	paint(node[v1][i], d1-1, c1);

}int main()

{    

    ios::sync_with_stdio(0);    

	memset(color, 0, sizeof color);    

	int N, M;    

	cin >> N >>M;    

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

	int a, b;        

	cin >> a >> b;        

	node[a].push_back(b);        

	node[b].push_back(a);    

	}    ///自己指向自己， 才能够自己跑到color[i][0]    

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

	node[i].push_back(i);    

	int q;    

	cin >> q;    

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

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

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

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

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

	cout<<color[i][0]<<endl;    

	return 0;

}


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

#define max(a,b) (a>b?a:b)

#define min(a,b) (a<b?a:b)

const int big=0x7fffffff;

using namespace std;

inline void read(int &x)

{

    x=0;char ch=getchar();int pd=1;

    while(ch<'0'||ch>'9'){if(ch=='-')pd=-pd;ch=getchar();}

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

    x*=pd;

}

inline void write(const int &x)

{

    char ggg[10001];int s=0;int tmp=x;

    if(tmp==0){putchar('0');return;}

    if(tmp<0){tmp=-tmp;putchar('-');}

    while(tmp>0){ggg[s++]=tmp%10+'0';tmp/=10;}

    while(s>0){putchar(ggg[--s]);}

}

const int N=1e5+233;

int mx[N],vis[N],t,h[N];



struct dd

{

	int end,nt;

}e[N<<1];



inline void add(int begin,int end)

{

	++t;

	e[t].end=end;

	e[t].nt=h[begin];

	h[begin]=t;

}



void dfs(int x,int d,int s)

{

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

	if(!vis[x])vis[x]=s;

	mx[x]=max(mx[x],d);

	if(!d)return;

	for(register int i=h[x];i;i=e[i].nt)

	{

		int u=e[i].end;

		dfs(u,d-1,s);

	}

}

const int Q=1e5+233;

int n,m,q,xx[N],d[N],c[N];







int main()

{

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

	read(n);

	read(m);

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

	{

		int xx,yy;

		read(xx);

		read(yy);

		add(xx,yy);

		add(yy,xx);

	}

	read(q);

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

	{

		read(xx[i]);

		read(d[i]);

		read(c[i]);

	}

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

	{

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

	}

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

	{

		write(vis[i]);

		putchar('\n');

	}

	return 0;

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

using namespace std;

typedef long long LL;

const int maxn = 100000+10;

int color[maxn][15];

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

vector <int> node[maxn];

void paint(int v1, int d1, int c1)

{    

    if(d1==-1)  return;    

	if(color[v1][d1] ) return;    

	color[v1][d1] = c1;    

	for(int i =0;i<node[v1].size();i++)        

	paint(node[v1][i], d1-1, c1);

}int main()

{    

    ios::sync_with_stdio(0);    

	memset(color, 0, sizeof color);    

	int N, M;    

	cin >> N >>M;    

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

	int a, b;        

	cin >> a >> b;        

	node[a].push_back(b);        

	node[b].push_back(a);    

	}    ///自己指向自己， 才能够自己跑到color[i][0]    

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

	node[i].push_back(i);    

	int q;    

	cin >> q;    

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

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

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

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

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

	cout<<color[i][0]<<endl;    

	return 0;

}


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



typedef long long ll;



const int maxn = 1e5+10;



int cor[maxn][14], qwq[maxn], qaq[maxn], c[maxn];



std::vector <int> pb[maxn];



int n, m, a, b, q;



void paint(int v1, int d1, int c1)

{

    if(d1==-1)  return;

    if(cor[v1][d1] ) return;

    cor[v1][d1] = c1;

    for(int i =0;i<pb[v1].size();i++)

        paint(pb[v1][i], d1-1, c1);

}



int read()

{

	int x=0, ch= getchar(), f=1;

	while(!isdigit(ch)){ if(ch == '-')f = -1, ch = getchar();}

	while(isdigit(ch)) x = x *10 + ch-'0', ch = getchar();

	return x * f;

} 



int main()

{

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

    for(int i=1;i<=m;i++) a=read(), b=read(), pb[a].push_back(b), pb[b].push_back(a);

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

    q=read();

    for(int i=1;i<=q;i++) qwq[i]=read(), qaq[i] = read(), c[i] = read();

    for(int i=q;i>=1;i--)  paint(qwq[i], qaq[i], c[i]);

    for(int i=1;i<=n;i++) std::cout<<cor[i][0]<<std::endl;

    return 0;

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

using namespace std;

typedef long long LL;

const int maxn = 100000+10;

int color[maxn][15];

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

vector <int> node[maxn];

void paint(int v1, int d1, int c1)

{    

    if(d1==-1)  return;    

	if(color[v1][d1] ) return;    

	color[v1][d1] = c1;    

	for(int i =0;i<node[v1].size();i++)        

	paint(node[v1][i], d1-1, c1);

}int main()

{    

    ios::sync_with_stdio(0);    

	memset(color, 0, sizeof color);    

	int N, M;    

	cin >> N >>M;    

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

	int a, b;        

	cin >> a >> b;        

	node[a].push_back(b);        

	node[b].push_back(a);    

	}    ///自己指向自己， 才能够自己跑到color[i][0]    

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

	node[i].push_back(i);    

	int q;    

	cin >> q;    

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

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

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

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

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

	cout<<color[i][0]<<endl;    

	return 0;

}


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



typedef long long ll;



const int maxn = 1e5 + 10;



int n, m, a, b, q, cor[maxn][14], qwq[maxn], qaq[maxn], c[maxn];



std::vector <int> pb[maxn];



void Work(int st, int deep, int cl)

{

    if(deep == -1) return;

    if(cor[st][deep]) return;

    cor[st][deep] = cl;

    for(int i = 0; i < pb[st].size(); ++ i) Work(pb[st][i], deep-1, cl);

}



int read()

{

	int x=0, ch= getchar(), f=1;

	while(!isdigit(ch)) if(ch == '-')f = -1, ch = getchar();

	while(isdigit(ch)) x = x *10 + ch-'0', ch = getchar();

	return x * f;

} 



int main()

{

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

    for(int i=1;i<=m;i++) a=read(), b=read(), pb[a].push_back(b), pb[b].push_back(a);

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

    q=read();

    for(int i=1;i<=q;i++) qwq[i]=read(), qaq[i] = read(), c[i] = read();

    for(int i=q;i>=1;i--) Work(qwq[i], qaq[i], c[i]);

    for(int i=1;i<=n;i++) std::cout<<cor[i][0]<<std::endl;

    return 0;

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

using namespace std;

inline int read(){

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

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

	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}

	return x*f;

}

#define MN 100005

int f[15][MN],c[MN],n,m,q,hr[MN],cnt;

struct edge{int to,nex;}e[MN*2];

inline void ins(int f,int t){

	e[++cnt]=(edge){t,hr[f]};hr[f]=cnt;

	e[++cnt]=(edge){f,hr[t]};hr[t]=cnt;	

}

int main(){

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

	for(int i=1;i<=m;++i) ins(read(),read());

	q=read();

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

		int x=read(),d=read();c[i]=read();

		f[d][x]=i;

	}

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

		for(int j=1;j<=n;++j){

			f[i-1][j]=max(f[i-1][j],f[i][j]);

			for(int k=hr[j];k;k=e[k].nex)

				f[i-1][e[k].to]=max(f[i-1][e[k].to],f[i][j]);	

		}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.646394298971205x):
#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);

}