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

using namespace std;

vector<int> a[100002];

int n,m,q,ans[100002],maindis[100002],v[100002],d[100002],c[100002];

void dfs(int k,int cc,int to){

	if(k<0){

		return;

	}

	if(k<=maindis[to]){

		return;

	}

	if(ans[to]==0){

		ans[to]=cc;

	}

	maindis[to]=k;

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

		dfs(k-1,cc,a[to][i]);

	}

}

int main(){

	cin>>n>>m;

	fill(maindis,maindis+100000,-1);

	memset(ans,0,sizeof(ans));

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

		int t1,t2;

		cin>>t1>>t2;

		a[t1].push_back(t2);

		a[t2].push_back(t1);

	}

	cin>>q;

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

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

	}

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

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

	}

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

		cout<<ans[i]<<endl;

	}

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

//		cout<<maindis[i]<<" ";

//	}

	return 0;

}

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



#define ll long long

#define ull unsigned long long

#define inf 0x3f3f3f3f

#define met(a, x) memset(a,x,sizeof(a))

#define mp make_pair;



using namespace std;

const int mod = 19e+7;

const int N = 1e5 + 10;

const int M = 1e6 + 10;

int m,n;

struct rec{

    int y,nex;

}edge[2*N];

int head[N],q1[N],q2[N],q3[N];

int val[N],maxd[N];

int cnt=0;

void add(int u,int v){

    edge[++cnt].y=v;

    edge[cnt].nex=head[u];

    head[u]=cnt;

}

void dfs(int u,int d,int x){

    if(maxd[u]>=d)

        return ;

    if(!val[u])

        val[u]=x;

    if(d==0)

        return;

    maxd[u]=d;

    for(int i=head[u];i;i=edge[i].nex){

        dfs(edge[i].y,d-1,x);

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cin>>n>>m;

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

        int a,b;

        cin>>a>>b;

        add(a,b);

        add(b,a);

    }

    int q;

    cin>>q;

    met(maxd,-1);

    met(val,0);

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

        cin>>q1[i]>>q2[i]>>q3[i];

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

        dfs(q1[i],q2[i],q3[i]);

    }

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

        cout<<val[i]<<endl;

    }

    return 0;

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

using namespace std;

vector<int> a[100002];

int n,m,q,ans[100002],maindis[100002],v[100002],d[100002],c[100002];

void dfs(int k,int cc,int to){

	if(k<0){

		return;

	}

	if(k<=maindis[to]){

		return;

	}

	if(ans[to]==0){

		ans[to]=cc;

	}

	maindis[to]=k;

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

		dfs(k-1,cc,a[to][i]);

	}

}

int main(){

	cin>>n>>m;

	fill(maindis,maindis+100000,-1);

	memset(ans,0,sizeof(ans));

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

		int t1,t2;

		cin>>t1>>t2;

		a[t1].push_back(t2);

		a[t2].push_back(t1);

	}

	cin>>q;

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

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

	}

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

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

	}

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

		cout<<ans[i]<<endl;

	}

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

//		cout<<maindis[i]<<" ";

//	}

	return 0;

}

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

#include <cstring>

#include <cstdio>

using namespace std;



int head[100005], tot, n, m, q, v[100005], d[100005], c[100005], ou[100005], maxd[100005];

struct edge {

	int to, nxt;

} G[300005];



inline void add(int u, int v) {

	tot++;

	G[tot].to = v;

	G[tot].nxt = head[u];

	head[u] = tot;

}



void dfs(int un, int ds, int c) {

	if(maxd[un] >= ds) return;

	if(!ou[un]) ou[un] = c;

	if(!ds) return;

	maxd[un] = ds;

	for (int i = head[un]; i; i = G[i].nxt) dfs(G[i].to, ds - 1, c);

}



int main() {

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

	int u, vd;

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

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

		add(u, vd); add(vd, u);

	}

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

	scanf ("%d", &q);

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

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

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

	return 0;

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



#define ll long long

#define ull unsigned long long

#define inf 0x3f3f3f3f

#define met(a, x) memset(a,x,sizeof(a))

#define mp make_pair;



using namespace std;

const int mod = 19e+7;

const int N = 1e5 + 10;

const int M = 1e6 + 10;

int m,n;

struct rec{

    int y,nex;

}edge[2*N];

int head[N],q1[N],q2[N],q3[N];

int val[N],maxd[N];

int cnt=0;

void add(int u,int v){

    edge[++cnt].y=v;

    edge[cnt].nex=head[u];

    head[u]=cnt;

}

void dfs(int u,int d,int x){

    if(maxd[u]>=d)

        return ;

    if(!val[u])

        val[u]=x;

    if(d==0)

        return;

    maxd[u]=d;

    for(int i=head[u];i;i=edge[i].nex){

        dfs(edge[i].y,d-1,x);

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cin>>n>>m;

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

        int a,b;

        cin>>a>>b;

        add(a,b);

        add(b,a);

    }

    int q;

    cin>>q;

    met(maxd,-1);

    met(val,0);

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

        cin>>q1[i]>>q2[i]>>q3[i];

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

        dfs(q1[i],q2[i],q3[i]);

    }

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

        cout<<val[i]<<endl;

    }

    return 0;

}

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

#include <cstring>

#include <cstdio>

using namespace std;



int head[100005], tot, n, m, q, v[100005], d[100005], c[100005], ou[100005], maxd[100005];

struct edge {

	int to, nxt;

} G[300005];



inline void add(int u, int v) {

	tot++;

	G[tot].to = v;

	G[tot].nxt = head[u];

	head[u] = tot;

}



void dfs(int un, int ds, int c) {

	if(maxd[un] >= ds) return;

	if(!ou[un]) ou[un] = c;

	if(!ds) return;

	maxd[un] = ds;

	for (int i = head[un]; i; i = G[i].nxt) dfs(G[i].to, ds - 1, c);

}



int main() {

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

	int u, vd;

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

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

		add(u, vd); add(vd, u);

	}

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

	scanf ("%d", &q);

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

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

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

	return 0;

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

using namespace std;

vector<int> a[100002];

int n,m,q,ans[100002],maindis[100002],v[100002],d[100002],c[100002];

void dfs(int k,int cc,int to){

	if(k<0){

		return;

	}

	if(k<=maindis[to]){

		return;

	}

	if(ans[to]==0){

		ans[to]=cc;

	}

	maindis[to]=k;

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

		dfs(k-1,cc,a[to][i]);

	}

}

int main(){

	cin>>n>>m;

	fill(maindis,maindis+100000,-1);

	memset(ans,0,sizeof(ans));

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

		int t1,t2;

		cin>>t1>>t2;

		a[t1].push_back(t2);

		a[t2].push_back(t1);

	}

	cin>>q;

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

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

	}

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

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

	}

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

		cout<<ans[i]<<endl;

	}

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

//		cout<<maindis[i]<<" ";

//	}

	return 0;

}

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

using namespace std ;

#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

int gi() {

	char cc = getchar() ; int cn = 0, flus = 1 ;

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

	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;

	return cn * flus ;

}

const int N = 1e5 + 5 ; 

const int M = 10 + 5 ; 

int n, m, cnt, dp[N][M], head[N], col[N] ; 

struct Q {

	int v, d, c ; 

} q[N] ;

struct E {

	int to, next ; 

} e[N << 1] ;

void add( int x, int y ) {

	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,

	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 

}

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

	if( d < 0 ) return ;

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

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

	dp[x][d] = 1 ; 

	Next( i, x ) {

		int v = e[i].to ; 

		dfs( v, d - 1, c ) ;

	}

}

signed main()

{

	n = gi(), m = gi() ; int u, v ;

	rep( i, 1, m ) u = gi(), v = gi(), add( u, v ) ;

	int T = gi() ;

	rep( i, 1, T ) q[i].v = gi(), q[i].d = gi(), q[i].c = gi() ;

	for( re int i = T; i; -- i ) {

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

	}

	rep( i, 1, n ) printf("%d\n", col[i] ) ;

	return 0 ;

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



#define ll long long

#define ull unsigned long long

#define inf 0x3f3f3f3f

#define met(a, x) memset(a,x,sizeof(a))

#define mp make_pair;



using namespace std;

const int mod = 19e+7;

const int N = 1e5 + 10;

const int M = 1e6 + 10;

int m,n;

struct rec{

    int y,nex;

}edge[2*N];

int head[N],q1[N],q2[N],q3[N];

int val[N],maxd[N];

int cnt=0;

void add(int u,int v){

    edge[++cnt].y=v;

    edge[cnt].nex=head[u];

    head[u]=cnt;

}

void dfs(int u,int d,int x){

    if(maxd[u]>=d)

        return ;

    if(!val[u])

        val[u]=x;

    if(d==0)

        return;

    maxd[u]=d;

    for(int i=head[u];i;i=edge[i].nex){

        dfs(edge[i].y,d-1,x);

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cin>>n>>m;

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

        int a,b;

        cin>>a>>b;

        add(a,b);

        add(b,a);

    }

    int q;

    cin>>q;

    met(maxd,-1);

    met(val,0);

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

        cin>>q1[i]>>q2[i]>>q3[i];

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

        dfs(q1[i],q2[i],q3[i]);

    }

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

        cout<<val[i]<<endl;

    }

    return 0;

}

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

using namespace std ;

#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

int gi() {

	char cc = getchar() ; int cn = 0, flus = 1 ;

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

	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;

	return cn * flus ;

}

const int N = 1e5 + 5 ; 

const int M = 10 + 5 ; 

int n, m, cnt, dp[N][M], head[N], col[N] ; 

struct Q {

	int v, d, c ; 

} q[N] ;

struct E {

	int to, next ; 

} e[N << 1] ;

void add( int x, int y ) {

	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,

	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 

}

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

	if( d < 0 ) return ;

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

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

	dp[x][d] = 1 ; 

	Next( i, x ) {

		int v = e[i].to ; 

		dfs( v, d - 1, c ) ;

	}

}

signed main()

{

	n = gi(), m = gi() ; int u, v ;

	rep( i, 1, m ) u = gi(), v = gi(), add( u, v ) ;

	int T = gi() ;

	rep( i, 1, T ) q[i].v = gi(), q[i].d = gi(), q[i].c = gi() ;

	for( re int i = T; i; -- i ) {

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

	}

	rep( i, 1, n ) printf("%d\n", col[i] ) ;

	return 0 ;

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

#include <cstring>

#include <cstdio>

using namespace std;



int head[100005], tot, n, m, q, v[100005], d[100005], c[100005], ou[100005], maxd[100005];

struct edge {

	int to, nxt;

} G[300005];



inline void add(int u, int v) {

	tot++;

	G[tot].to = v;

	G[tot].nxt = head[u];

	head[u] = tot;

}



void dfs(int un, int ds, int c) {

	if(maxd[un] >= ds) return;

	if(!ou[un]) ou[un] = c;

	if(!ds) return;

	maxd[un] = ds;

	for (int i = head[un]; i; i = G[i].nxt) dfs(G[i].to, ds - 1, c);

}



int main() {

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

	int u, vd;

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

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

		add(u, vd); add(vd, u);

	}

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

	scanf ("%d", &q);

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

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

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

	return 0;

}

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

using namespace std ;

#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

int gi() {

	char cc = getchar() ; int cn = 0, flus = 1 ;

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

	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;

	return cn * flus ;

}

const int N = 1e5 + 5 ; 

const int M = 10 + 5 ; 

int n, m, cnt, dp[N][M], head[N], col[N] ; 

struct Q {

	int v, d, c ; 

} q[N] ;

struct E {

	int to, next ; 

} e[N << 1] ;

void add( int x, int y ) {

	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,

	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 

}

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

	if( d < 0 ) return ;

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

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

	dp[x][d] = 1 ; 

	Next( i, x ) {

		int v = e[i].to ; 

		dfs( v, d - 1, c ) ;

	}

}

signed main()

{

	n = gi(), m = gi() ; int u, v ;

	rep( i, 1, m ) u = gi(), v = gi(), add( u, v ) ;

	int T = gi() ;

	rep( i, 1, T ) q[i].v = gi(), q[i].d = gi(), q[i].c = gi() ;

	for( re int i = T; i; -- i ) {

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

	}

	rep( i, 1, n ) printf("%d\n", col[i] ) ;

	return 0 ;

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

using namespace std;



const int N = 300001;

int n, m, tot = 0, q;

int head[N], Next[N], ver[N], num[N];

int ans[N][20] = {};

struct edge{

	int x, y, z;

}a[N];



vector <int> vis[N];



void dfs(int x,int y,int z) {

	if (y == -1) return;

	if (ans[x][y]) return;

	ans[x][y] = z;

	for (int i=0;i<vis[x].size();++i) dfs(vis[x][i], y-1, z);

}



int main() {

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

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

		int x, y;

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

		vis[x].push_back(y);

		vis[y].push_back(x);

	}

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

	scanf("%d",&q);

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

		int x, y, z;

		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);

	}

	for (int i=q;i;--i) dfs(a[i].x, a[i].y, a[i].z);

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

	return 0;

}

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

using namespace std ;

#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

int gi() {

	char cc = getchar() ; int cn = 0, flus = 1 ;

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

	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;

	return cn * flus ;

}

const int N = 1e5 + 5 ; 

const int M = 10 + 5 ; 

int n, m, cnt, dp[N][M], head[N], col[N] ; 

struct Q {

	int v, d, c ; 

} q[N] ;

struct E {

	int to, next ; 

} e[N << 1] ;

void add( int x, int y ) {

	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,

	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 

}

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

	if( d < 0 ) return ;

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

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

	dp[x][d] = 1 ; 

	Next( i, x ) {

		int v = e[i].to ; 

		dfs( v, d - 1, c ) ;

	}

}

signed main()

{

	n = gi(), m = gi() ; int u, v ;

	rep( i, 1, m ) u = gi(), v = gi(), add( u, v ) ;

	int T = gi() ;

	rep( i, 1, T ) q[i].v = gi(), q[i].d = gi(), q[i].c = gi() ;

	for( re int i = T; i; -- i ) {

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

	}

	rep( i, 1, n ) printf("%d\n", col[i] ) ;

	return 0 ;

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

    using namespace std;

    int ans[100003],n,m,q,do1[100003],do2[100003],do3[100003];

    vector<int>v[100005];

    int vis[100003];

    void dfs(int a,int b,int c){

    	if(b==-1)return;

    	if(b<=vis[a])return;

    	vis[a]=b;

    	if(!ans[a])ans[a]=c;

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

    		dfs(v[a][i],b-1,c);

    }

    int main(){

    	cin>>n>>m;

    	for(int i=0;i<=100002;i++)vis[i]=-1;

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

    	{

    		int a,b;

    		cin>>a>>b;

    		v[a].push_back(b);

    		v[b].push_back(a);

    	}

    	cin>>q;

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

    		cin>>do1[i]>>do2[i]>>do3[i];

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

    		dfs(do1[i],do2[i],do3[i]);

    	}

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

    }

// Faster C++ solution for the same problem (measured speedup: 1.1132486514192415x):
//**************************

//*** writer  :  Alex Hu **

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



#include<bits/stdc++.h>



using namespace std;



#define CLEAN(a,b) memset(a,b,sizeof(a))

#define mkp make_pair

#define pb push_back

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



typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

 

const int maxn=100005,maxd=11;

int c[maxn][maxd];

int col[maxn];

vector<int> e[maxn];

 

int main(){

 

	int n,m,q;

	cin>>n>>m;

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

		int a,b;

		cin>>a>>b;

		--a;--b;

		e[a].push_back(b);

		e[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=maxd-2;i>=0;i--){

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

			for(int u=0;u<e[v].size();u++){

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

			}

		}

	}

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

		int res=0;

		for(int d=0;d<maxd;d++){

			res=max(res,c[v][d]);

		}

		cout<<col[res]<<endl;

	}

	return 0;

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

    using namespace std;

    int ans[100003],n,m,q,do1[100003],do2[100003],do3[100003];

    vector<int>v[100005];

    int vis[100003];

    void dfs(int a,int b,int c){

    	if(b==-1)return;

    	if(b<=vis[a])return;

    	vis[a]=b;

    	if(!ans[a])ans[a]=c;

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

    		dfs(v[a][i],b-1,c);

    }

    int main(){

    	cin>>n>>m;

    	for(int i=0;i<=100002;i++)vis[i]=-1;

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

    	{

    		int a,b;

    		cin>>a>>b;

    		v[a].push_back(b);

    		v[b].push_back(a);

    	}

    	cin>>q;

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

    		cin>>do1[i]>>do2[i]>>do3[i];

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

    		dfs(do1[i],do2[i],do3[i]);

    	}

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

    }

// Faster C++ solution for the same problem (measured speedup: 3.9671582761780617x):
//**************************

//*** writer  :  Alex Hu **

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



#include<bits/stdc++.h>



using namespace std;



#define CLEAN(a,b) memset(a,b,sizeof(a))

#define mkp make_pair

#define pb push_back

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



typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;



const int maxn=1e5+10;



int n,m,cnt,tot,fst[maxn],pnt[maxn<<1],nxt[maxn<<1],ans[maxn],dp[maxn][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 x,y;

	rept(i,1,m+1)

	{

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

		add(x,y);

		add(y,x);

	}

	scanf("%d",&cnt);

	rept(i,1,cnt+1)

	{

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

		dp[x][y]=i;

	}

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

	{

		rept(x,1,n+1)

		{

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

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

		}

	}

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

	return 0;

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

//*** writer  :  Alex Hu **

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



#include<bits/stdc++.h>



using namespace std;



#define CLEAN(a,b) memset(a,b,sizeof(a))

#define mkp make_pair

#define pb push_back

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



typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

 

const int maxn=100005,maxd=11;

int c[maxn][maxd];

int col[maxn];

vector<int> e[maxn];

 

int main(){

 

	int n,m,q;

	cin>>n>>m;

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

		int a,b;

		cin>>a>>b;

		--a;--b;

		e[a].push_back(b);

		e[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=maxd-2;i>=0;i--){

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

			for(int u=0;u<e[v].size();u++){

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

			}

		}

	}

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

		int res=0;

		for(int d=0;d<maxd;d++){

			res=max(res,c[v][d]);

		}

		cout<<col[res]<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.563746957649329x):
//**************************

//*** writer  :  Alex Hu **

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



#include<bits/stdc++.h>



using namespace std;



#define CLEAN(a,b) memset(a,b,sizeof(a))

#define mkp make_pair

#define pb push_back

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



typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;



const int maxn=1e5+10;



int n,m,cnt,tot,fst[maxn],pnt[maxn<<1],nxt[maxn<<1],ans[maxn],dp[maxn][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 x,y;

	rept(i,1,m+1)

	{

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

		add(x,y);

		add(y,x);

	}

	scanf("%d",&cnt);

	rept(i,1,cnt+1)

	{

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

		dp[x][y]=i;

	}

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

	{

		rept(x,1,n+1)

		{

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

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

		}

	}

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

	return 0;

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

*  Author: BD747  *

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

#include<algorithm>

#include<cstdio>

#include<iostream>

#include<cstring>

#include<cmath>

#include<map>

#include<queue>

#include<set>

#include<sstream>

#include<stack>

#include<string>

#include<vector>

using namespace std;



int col[100005];

vector<int> v[100005];

int n,m;

int __d,_col;

int use[100005];

int _v[100005],d[100005],c[100005];

inline void dfs(int x,int d){

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

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

	use[x]=d;

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

		int e=v[x][i];

		if(d) dfs(e,d-1);

	}

}



int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	int i,j,q;

	cin>>n>>m;

    int x,y,z;

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

    	cin>>x>>y;

    	v[x].push_back(y);

    	v[y].push_back(x);

	}

	cin>>q;

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

	for(j=1;j<=q;++j) cin>>_v[j]>>d[j]>>c[j];

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

		_col=c[i];

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

	}

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

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1179223861146503x):
/******************

*  Author: BD747  *

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

//Endagorion

#include<algorithm>

#include<cstdio>

#include<iostream>

#include<cstring>

#include<cmath>

#include<map>

#include<queue>

#include<set>

#include<sstream>

#include<stack>

#include<string>

#include<vector>

#include<bits/stdc++.h>

using namespace std;



const int maxn=100005,maxd=11;

int c[maxn][maxd];

int col[maxn];

vector<int> e[maxn];



int main(){



	int n,m,q;

	cin>>n>>m;

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

		int a,b;

		cin>>a>>b;

		--a;--b;

		e[a].push_back(b);

		e[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=maxd-2;i>=0;i--){

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

			for(int u=0;u<e[v].size();u++){

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

			}

		}

	}

	

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

		int res=0;

		for(int d=0;d<maxd;d++){

			res=max(res,c[v][d]);

		}

		cout<<col[res]<<endl;

	}



	return 0;

}