stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 1000 * 100 + 47;



struct Item

{

	int v, d, c;

};



Item Q[MAX];

vector<int> g[MAX];

int U[MAX];

int D[MAX];

int C[MAX];

int iter;



void dfs(int v, int d, int curD, int color)

{

	if (d > curD) return;

	if (curD - d <= D[v]) return;

	D[v] = curD - d;

	if (C[v] == 0) C[v] = color;

	FOR(i, 0, SZ(g[v]))

	{

		int to = g[v][i];

		dfs(to, d + 1, curD, color);

	}

}



int main()

{

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

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

	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;

	cin >> n >> m;

	FOR(i, 0, m)

	{

		int a, b;

		cin >> a >> b;

		a--;

		b--;

		g[a].push_back(b);

		g[b].push_back(a);

	}



	int q;

	cin >> q;

	FOR(i, 0, q)

	{

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

		Q[i].v--;

	}



	reverse(Q, Q + q);

	FILL(D, -1);

	FOR(i, 0, q)

	{

		dfs(Q[i].v, 0, Q[i].d, Q[i].c);

	}



	FOR(i, 0, n)

	{

		//cout << i + 1 << ": " << C[i] << "\n";

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



	}

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

struct E{int v,next;}g[200005];

int n,m,q,h[100005],v[100005],d[100005],c[100005],color[100005],t,dis[100005];

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;

}

void ins(int u,int v){g[++t].v=v,g[t].next=h[u],h[u]=t;}

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

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

	dis[v]=d; if(color[v]==0) color[v]=c;

	for(int i=h[v];i;i=g[i].next) dfs(g[i].v,d-1,c);

}

int main(){

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

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

		int u,v;

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

		ins(u,v),ins(v,u);

	}

	q=read();

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

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

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

}

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

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

struct E{int v,next;}g[200005];

int n,m,q,h[100005],v[100005],d[100005],c[100005],color[100005],t,dis[100005];

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;

}

void ins(int u,int v){g[++t].v=v,g[t].next=h[u],h[u]=t;}

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

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

	dis[v]=d; if(color[v]==0) color[v]=c;

	for(int i=h[v];i;i=g[i].next) dfs(g[i].v,d-1,c);

}

int main(){

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

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

		int u,v;

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

		ins(u,v),ins(v,u);

	}

	q=read();

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

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

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

}

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

 } 

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

struct E{int v,next;}g[200005];

int n,m,q,h[100005],v[100005],d[100005],c[100005],color[100005],t,dis[100005];

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;

}

void ins(int u,int v){g[++t].v=v,g[t].next=h[u],h[u]=t;}

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

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

	dis[v]=d; if(color[v]==0) color[v]=c;

	for(int i=h[v];i;i=g[i].next) dfs(g[i].v,d-1,c);

}

int main(){

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

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

		int u,v;

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

		ins(u,v),ins(v,u);

	}

	q=read();

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

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

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

}

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

}


// Optimized solution to the same problem (faster):
/*   三玖天下第一！！！  */

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

}


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

}

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

}

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

}


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

}

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

}

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

}


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

}


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

}


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

}

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

}


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

}

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

}


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

}

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

}


// Fastest known solution for this problem: