stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//

//  main.cpp

//  backToProblemSolving

//

//  Created by Khaled Abdelfattah on 6/27/17.

//  Copyright © 2017 Khaled Abdelfattah. All rights reserved.

//



#include <bits/stdc++.h>

// #include <iostream>

using namespace std;

//#include "stdc++.h"



typedef long long ll;

#define MAX 1000000000

#define BASE1 23

#define BASE2 31

#define MOD1 1000000007

#define MOD2 217645177

#define eps 1e-6



int colors[100005];

vector<int> adjList[100005];

bool visited[100005][15];

void DFS (int node, int d, int c) {

    if (d < 0 || visited[node][d])

        return;

    visited[node][d] = true;

    if (colors[node] == 0)

        colors[node] = c;

    for (int i : adjList[node])

        DFS(i, d - 1, c);

}

int main() {

    int n, m;

    cin >> n >> m;

    memset(colors, 0, n);

    memset(visited, 0, sizeof visited);

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

        int u, v;

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

        v--, u--;

        adjList[u].push_back(v);

        adjList[v].push_back(u);

    }

    int q;

    cin >> q;

    pair<pair<int, int>, int> *quers = new pair<pair<int, int>, int> [q];

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

        int s, d, c;

        scanf("%d %d %d", &s, &d, &c);

        quers[i] = {{s - 1, d}, c};

    }

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

        DFS(quers[i].first.first, quers[i].first.second, quers[i].second);

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

        cout << colors[i] << endl;

    return 0;

}


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

int n,m;

int q;

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

vector<int> g[100005];

int colour[100005];

int mindis[100005];

inline void dfs(int x,int dleft,int c)

{

	if(dleft<=mindis[x])

	{

		return;

	}

	mindis[x]=dleft;

	if(colour[x]==0)

	{

		colour[x]=c;

	}

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

	{

		dfs(g[x][i],dleft-1,c);

	}

}

int main()

{

	cin>>n>>m;

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

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

	{

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

	}

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

	{

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

	}

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

	{

		cout<<colour[i]<<endl;

	}

	return 0;

}

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



const int N = 1e5 + 10;



vector <int> G[N];

int rec[N], color[N], ver[N], d[N], c[N];



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

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

	if (~rec[x] && dist <= rec[x]) return;

	rec[x] = dist;

	if (dist == 0) return;

	for (int i = 0; i < G[x].size(); i++) dfs(G[x][i], dist - 1, col);

}



int main(){

	int n, m, q, u, v;

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

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

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

		G[u].push_back(v);

		G[v].push_back(u);

	}

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

	memset(color, 0, sizeof(color));

	scanf("%d",&q);

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

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

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

	return 0;

}

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

#include <vector>



const int MAXN = 1e5 + 100;



int n, m, Q;

int x[MAXN], d[MAXN], c[MAXN];



std::vector<int> edge[MAXN << 1];



int col[MAXN][20];



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

	if (d == -1 || col[x][d])

		return;

	col[x][d] = c;

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

		int y = edge[x][i];

		Dfs(y, d - 1, c);

	}

}



int main() {

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

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

		int u, v;

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

		edge[u].push_back(v), edge[v].push_back(u);

	}

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

		edge[i].push_back(i);



	scanf("%d", &Q);

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

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



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

		Dfs(x[i], d[i], c[i]);

	

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

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

	return 0;

}

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

//  main.cpp

//  backToProblemSolving

//

//  Created by Khaled Abdelfattah on 6/27/17.

//  Copyright © 2017 Khaled Abdelfattah. All rights reserved.

//



#include <bits/stdc++.h>

// #include <iostream>

using namespace std;

//#include "stdc++.h"



typedef long long ll;

#define MAX 1000000000

#define BASE1 23

#define BASE2 31

#define MOD1 1000000007

#define MOD2 217645177

#define eps 1e-6



int colors[100005];

vector<int> adjList[100005];

bool visited[100005][15];

void DFS (int node, int d, int c) {

    if (d < 0 || visited[node][d])

        return;

    visited[node][d] = true;

    if (colors[node] == 0)

        colors[node] = c;

    for (int i : adjList[node])

        DFS(i, d - 1, c);

}

int main() {

    int n, m;

    cin >> n >> m;

    memset(colors, 0, n);

    memset(visited, 0, sizeof visited);

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

        int u, v;

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

        v--, u--;

        adjList[u].push_back(v);

        adjList[v].push_back(u);

    }

    int q;

    cin >> q;

    pair<pair<int, int>, int> *quers = new pair<pair<int, int>, int> [q];

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

        int s, d, c;

        scanf("%d %d %d", &s, &d, &c);

        quers[i] = {{s - 1, d}, c};

    }

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

        DFS(quers[i].first.first, quers[i].first.second, quers[i].second);

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

        cout << colors[i] << endl;

    return 0;

}


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

#include <cctype>

#include <algorithm>

#include <cstdio>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

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

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

    return f*x;

}

const int N = 1e5+5;

struct Edge

{

    int next, to;

    Edge(int next = 0, int to = 0):next(next), to(to) {};

}edge[N<<1];

int tot, head[N];

void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }

void add(int x, int y) { _add(x, y), _add(y, x); }

int n, m, q, col[N], u[N], d[N], w[N], f[N];

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

{

    if(f[x]>>d&1) return;

    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;

    for(int i = head[x]; i&&d; i = edge[i].next)

    {

        int y = edge[i].to;

        dfs(y, d-1, c);

    }

}

int main()

{

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

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

    q = read();

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

    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);

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

    return 0;

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

using namespace std;

int n,m;

int q;

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

vector<int> g[100005];

int colour[100005];

int mindis[100005];

inline void dfs(int x,int dleft,int c)

{

	if(dleft<=mindis[x])

	{

		return;

	}

	mindis[x]=dleft;

	if(colour[x]==0)

	{

		colour[x]=c;

	}

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

	{

		dfs(g[x][i],dleft-1,c);

	}

}

int main()

{

	cin>>n>>m;

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

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

	{

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

	}

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

	{

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

	}

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

	{

		cout<<colour[i]<<endl;

	}

	return 0;

}

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

#include <cctype>

#include <algorithm>

#include <cstdio>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

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

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

    return f*x;

}

const int N = 1e5+5;

struct Edge

{

    int next, to;

    Edge(int next = 0, int to = 0):next(next), to(to) {};

}edge[N<<1];

int tot, head[N];

void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }

void add(int x, int y) { _add(x, y), _add(y, x); }

int n, m, q, col[N], u[N], d[N], w[N], f[N];

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

{

    if(f[x]>>d&1) return;

    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;

    for(int i = head[x]; i&&d; i = edge[i].next)

    {

        int y = edge[i].to;

        dfs(y, d-1, c);

    }

}

int main()

{

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

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

    q = read();

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

    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);

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

    return 0;

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

using namespace std;



const int N = 1e5 + 10;



vector <int> G[N];

int rec[N], color[N], ver[N], d[N], c[N];



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

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

	if (~rec[x] && dist <= rec[x]) return;

	rec[x] = dist;

	if (dist == 0) return;

	for (int i = 0; i < G[x].size(); i++) dfs(G[x][i], dist - 1, col);

}



int main(){

	int n, m, q, u, v;

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

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

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

		G[u].push_back(v);

		G[v].push_back(u);

	}

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

	memset(color, 0, sizeof(color));

	scanf("%d",&q);

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

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

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

	return 0;

}

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

#include <cctype>

#include <algorithm>

#include <cstdio>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

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

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

    return f*x;

}

const int N = 1e5+5;

struct Edge

{

    int next, to;

    Edge(int next = 0, int to = 0):next(next), to(to) {};

}edge[N<<1];

int tot, head[N];

void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }

void add(int x, int y) { _add(x, y), _add(y, x); }

int n, m, q, col[N], u[N], d[N], w[N], f[N];

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

{

    if(f[x]>>d&1) return;

    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;

    for(int i = head[x]; i&&d; i = edge[i].next)

    {

        int y = edge[i].to;

        dfs(y, d-1, c);

    }

}

int main()

{

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

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

    q = read();

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

    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);

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

    return 0;

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

#include <vector>



const int MAXN = 1e5 + 100;



int n, m, Q;

int x[MAXN], d[MAXN], c[MAXN];



std::vector<int> edge[MAXN << 1];



int col[MAXN][20];



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

	if (d == -1 || col[x][d])

		return;

	col[x][d] = c;

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

		int y = edge[x][i];

		Dfs(y, d - 1, c);

	}

}



int main() {

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

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

		int u, v;

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

		edge[u].push_back(v), edge[v].push_back(u);

	}

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

		edge[i].push_back(i);



	scanf("%d", &Q);

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

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



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

		Dfs(x[i], d[i], c[i]);

	

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

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

	return 0;

}

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

#include <cctype>

#include <algorithm>

#include <cstdio>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

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

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

    return f*x;

}

const int N = 1e5+5;

struct Edge

{

    int next, to;

    Edge(int next = 0, int to = 0):next(next), to(to) {};

}edge[N<<1];

int tot, head[N];

void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }

void add(int x, int y) { _add(x, y), _add(y, x); }

int n, m, q, col[N], u[N], d[N], w[N], f[N];

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

{

    if(f[x]>>d&1) return;

    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;

    for(int i = head[x]; i&&d; i = edge[i].next)

    {

        int y = edge[i].to;

        dfs(y, d-1, c);

    }

}

int main()

{

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

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

    q = read();

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

    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);

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

    return 0;

}
// Slower C++ solution:
#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;

}

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

#include <cctype>

#include <algorithm>

#include <cstdio>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

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

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

    return f*x;

}

const int N = 1e5+5;

struct Edge

{

    int next, to;

    Edge(int next = 0, int to = 0):next(next), to(to) {};

}edge[N<<1];

int tot, head[N];

void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }

void add(int x, int y) { _add(x, y), _add(y, x); }

int n, m, q, col[N], u[N], d[N], w[N], f[N];

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

{

    if(f[x]>>d&1) return;

    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;

    for(int i = head[x]; i&&d; i = edge[i].next)

    {

        int y = edge[i].to;

        dfs(y, d-1, c);

    }

}

int main()

{

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

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

    q = read();

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

    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);

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

    return 0;

}
// Slower C++ solution:
//

//  main.cpp

//  backToProblemSolving

//

//  Created by Khaled Abdelfattah on 6/27/17.

//  Copyright © 2017 Khaled Abdelfattah. All rights reserved.

//



#include <bits/stdc++.h>

// #include <iostream>

using namespace std;

//#include "stdc++.h"



typedef long long ll;

#define MAX 1000000000

#define BASE1 23

#define BASE2 31

#define MOD1 1000000007

#define MOD2 217645177

#define eps 1e-6



int colors[100005];

vector<int> adjList[100005];

bool visited[100005][15];

void DFS (int node, int d, int c) {

    if (d < 0 || visited[node][d])

        return;

    visited[node][d] = true;

    if (colors[node] == 0)

        colors[node] = c;

    for (int i : adjList[node])

        DFS(i, d - 1, c);

}

int main() {

    int n, m;

    cin >> n >> m;

    memset(colors, 0, n);

    memset(visited, 0, sizeof visited);

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

        int u, v;

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

        v--, u--;

        adjList[u].push_back(v);

        adjList[v].push_back(u);

    }

    int q;

    cin >> q;

    pair<pair<int, int>, int> *quers = new pair<pair<int, int>, int> [q];

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

        int s, d, c;

        scanf("%d %d %d", &s, &d, &c);

        quers[i] = {{s - 1, d}, c};

    }

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

        DFS(quers[i].first.first, quers[i].first.second, quers[i].second);

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

        cout << colors[i] << endl;

    return 0;

}


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

using namespace std;

const int maxn=101000;



struct edge{

	int to,nxt;

}e[maxn<<1];

int head[maxn],tot,n,m,q,dis[maxn],col[maxn];

void add(int x,int y)

{

	e[++tot].to=y;

	e[tot].nxt=head[x];

	head[x]=tot;

}



struct opte{

	int p,d,c;

}opt[maxn];



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

{

	if(dis[x]>=d)return ;//剪枝 

	dis[x]=d;

	if(!col[x])col[x]=c;//最后一次的颜色 

	if(!d)return ;

	for(int i=head[x];i;i=e[i].nxt)

	{

		int y=e[i].to;

		dfs(y,d-1,c);

	}

}



int main()

{

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

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

	{

		int x,y;

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

		add(x,y);add(y,x);

	}

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

	scanf("%d",&q);

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

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

		dfs(opt[i].p,opt[i].d,opt[i].c);

	for(int i=1;i<=n;i++)cout<<col[i]<<"\n";

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

using namespace std;

int n,m;

int q;

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

vector<int> g[100005];

int colour[100005];

int mindis[100005];

inline void dfs(int x,int dleft,int c)

{

	if(dleft<=mindis[x])

	{

		return;

	}

	mindis[x]=dleft;

	if(colour[x]==0)

	{

		colour[x]=c;

	}

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

	{

		dfs(g[x][i],dleft-1,c);

	}

}

int main()

{

	cin>>n>>m;

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

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

	{

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

	}

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

	{

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

	}

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

	{

		cout<<colour[i]<<endl;

	}

	return 0;

}

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

using namespace std;

const int maxn=101000;



struct edge{

	int to,nxt;

}e[maxn<<1];

int head[maxn],tot,n,m,q,dis[maxn],col[maxn];

void add(int x,int y)

{

	e[++tot].to=y;

	e[tot].nxt=head[x];

	head[x]=tot;

}



struct opte{

	int p,d,c;

}opt[maxn];



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

{

	if(dis[x]>=d)return ;//剪枝 

	dis[x]=d;

	if(!col[x])col[x]=c;//最后一次的颜色 

	if(!d)return ;

	for(int i=head[x];i;i=e[i].nxt)

	{

		int y=e[i].to;

		dfs(y,d-1,c);

	}

}



int main()

{

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

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

	{

		int x,y;

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

		add(x,y);add(y,x);

	}

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

	scanf("%d",&q);

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

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

		dfs(opt[i].p,opt[i].d,opt[i].c);

	for(int i=1;i<=n;i++)cout<<col[i]<<"\n";

}