Language: C++

#include<stdio.h>
#include<vector>
#include<queue>
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
/*
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
*/
void reader(int *x) { int k, m = 0; *x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { *x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; *x = (*x) * 10 + k - '0'; }if (m)(*x) = -(*x); }
void reader(int *x, int *y) { reader(x); reader(y); }
void reader(int *x, int *y, int *z) { reader(x); reader(y); reader(z); }
void writer(int x, char c) { int i, sz = 0, m = 0; char buf[10]; if (x<0)m = 1, x = -x; while (x)buf[sz++] = x % 10, x /= 10; if (!sz)buf[sz++] = 0; if (m)mypc('-'); while (sz--)mypc(buf[sz] + '0'); mypc(c); }

vector<int>E[100000];
int d1[100000];
int c1[100000], c2[100000];
int que[100000];
int k[100000][12], t[100000][12];
signed main() {
	int n, m; reader(&n, &m);
	rep(i, m) {
		int a, b; reader(&a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
	}
	memset(c2, -1, sizeof(c2));
	int q; reader(&q);
	memset(k, -1, sizeof(k));
	rep(i, q) {
		int v, d, c; reader(&v, &d, &c); v--;
		k[v][d] = i; t[v][d] = c;
	}
	rep(i, n) {
		for (int j = 9; j >= 0; j--) {
			if (k[i][j] < k[i][j + 1]) {
				k[i][j] = k[i][j + 1];
				t[i][j] = t[i][j + 1];
			}
		}
		int s = 0, g = 0;
		if (c2[i] < k[i][0]) {
			c1[i] = t[i][0]; c2[i] = k[i][0];
		}
		memset(d1, -1, sizeof(d1));
		d1[i] = 0;
		if (k[i][1] != -1)que[g++] = i;
		while (s != g) {
			int p = que[s++];
			int siz = E[p].size();
			rep(j, siz) {
				int u = E[p][j];
				if (d1[u] == -1) {
					d1[u] = d1[p] + 1;
					if (k[i][d1[u]] > c2[u]) {
						c1[u] = t[i][d1[u]]; c2[u] = k[i][d1[u]];
					}
					if (k[i][d1[u] + 1] != -1)que[g++] = u;
				}
			}
		}
	}
	rep(i, n)writer(c1[i], '\n');
}

Compiler output:
a.cc: In function 'void reader(int*)':
a.cc:18:56: error: 'mygc' was not declared in this scope
   18 | void reader(int *x) { int k, m = 0; *x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { *x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; *x = (*x) * 10 + k - '0'; }if (m)(*x) = -(*x); }
      |                                                        ^~~~
a.cc:18:157: error: 'mygc' was not declared in this scope
   18 | void reader(int *x) { int k, m = 0; *x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { *x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; *x = (*x) * 10 + k - '0'; }if (m)(*x) = -(*x); }
      |                                                                                                                                                             ^~~~
a.cc: In function 'void writer(int, char)':
a.cc:21:156: error: 'mypc' was not declared in this scope
   21 | void writer(int x, char c) { int i, sz = 0, m = 0; char buf[10]; if (x<0)m = 1, x = -x; while (x)buf[sz++] = x % 10, x /= 10; if (!sz)buf[sz++] = 0; if (m)mypc('-'); while (sz--)mypc(buf[sz] + '0'); mypc(c); }
      |                                                                                                                                                            ^~~~
a.cc:21:179: error: 'mypc' was not declared in this scope
   21 | void writer(int x, char c) { int i, sz = 0, m = 0; char buf[10]; if (x<0)m = 1, x = -x; while (x)buf[sz++] = x % 10, x /= 10; if (!sz)buf[sz++] = 0; if (m)mypc('-'); while (sz--)mypc(buf[sz] + '0'); mypc(c); }
      |                                                                                                                                                                                   ^~~~
a.cc:21:200: error: 'mypc' was not declared in this scope
   21 | void writer(int x, char c) { int i, sz = 0, m = 0; char buf[10]; if (x<0)m = 1, x = -x; while (x)buf[sz++] = x % 10, x /= 10; if (!sz)buf[sz++] = 0; if (m)mypc('-'); while (sz--)mypc(buf[sz] + '0'); mypc(c); }
      |                                                                                                                                                                                                        ^~~~
a.cc: In function 'int main()':
a.cc:34:9: error: 'memset' was not declared in this scope
   34 |         memset(c2, -1, sizeof(c2));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<queue>
  +++ |+#include <cstring>
    4 | #define getchar_unlocked getchar