Language: C++

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

vvi to;

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  to = vvi(n);
  rep(i,m) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  vi vq, dq, cq;
  int q;
  scanf("%d",&q);
  rep(i,q) {
    vq.pb(in()-1);
    dq.pb(in());
    cq.pb(in());
  }
  vp p(n);
  drep(qi,q) {
    int v = vq[qi];
    int d = dq[qi];
    int c = cq[qi];
    queue<int> q;
    if (p[v].fi >= d) continue;
    p[v] = P(d,c);
    q.push(v);
    while (sz(q)) {
      v = q.front(); q.pop();
      for (int u : to[v]) {
        P x(p[v]);
        x.fi--;
        if (p[u].fi >= x.fi) continue;
        p[u] = x;
        q.push(u);
      }
    }
  }
  rep(i,n) {
    printf("%d\n",p[i].se);
  }
  return 0;
}




















#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

vvi to;

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  to = vvi(n);
  rep(i,m) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  vi vq, dq, cq;
  int q;
  scanf("%d",&q);
  rep(i,q) {
    vq.pb(in()-1);
    dq.pb(in());
    cq.pb(in());
  }
  vp p(n);
  drep(qi,q) {
    int v = vq[qi];
    int d = dq[qi];
    int c = cq[qi];
    queue<int> q;
    if (p[v].fi >= d) continue;
    p[v] = P(d,c);
    q.push(v);
    while (sz(q)) {
      v = q.front(); q.pop();
      for (int u : to[v]) {
        P x(p[v]);
        x.fi--;
        if (p[u].fi >= x.fi) continue;
        p[u] = x;
        q.push(u);
      }
    }
  }
  rep(i,n) {
    printf("%d\n",p[i].se);
  }
  return 0;
}






















Compiler output:
a.cc:181:12: error: redefinition of 'int in()'
  181 | inline int in() { int x; scanf("%d",&x); return x;}
      |            ^~
a.cc:50:12: note: 'int in()' previously defined here
   50 | inline int in() { int x; scanf("%d",&x); return x;}
      |            ^~
a.cc:182:13: error: redefinition of 'void priv(vi)'
  182 | inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
      |             ^~~~
a.cc:51:13: note: 'void priv(vi)' previously defined here
   51 | inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
      |             ^~~~
a.cc:183:30: error: redefinition of 'template<class T> std::istream& operator>>(std::istream&, std::vector<_Tp>&)'
  183 | template<typename T>istream& operator>>(istream&i,vector<T>&v)
      |                              ^~~~~~~~
a.cc:52:30: note: 'template<class T> std::istream& operator>>(std::istream&, std::vector<_Tp>&)' previously declared here
   52 | template<typename T>istream& operator>>(istream&i,vector<T>&v)
      |                              ^~~~~~~~
a.cc:185:28: error: redefinition of 'template<class T> std::string join(const std::vector<_Tp>&)'
  185 | template<typename T>string join(const vector<T>&v)
      |                            ^~~~
a.cc:54:28: note: 'template<class T> std::string join(const std::vector<_Tp>&)' previously declared here
   54 | template<typename T>string join(const vector<T>&v)
      |                            ^~~~
a.cc:187:30: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  187 | template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
      |                              ^~~~~~~~
a.cc:56:30: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   56 | template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
      |                              ^~~~~~~~
a.cc:189:43: error: redefinition of 'template<class T1, class T2> std::istream& operator>>(std::istream&, std::pair<_T1, _T2>&)'
  189 | template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
      |                                           ^~~~~~~~
a.cc:58:43: note: 'template<class T1, class T2> std::istream& operator>>(std::istream&, std::pair<_T1, _T2>&)' previously declared here
   58 | template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
      |                                           ^~~~~~~~
a.cc:191:43: error: redefinition of 'template<class T1, class T2> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
  191 | template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
      |                                           ^~~~~~~~
a.cc:60:43: note: 'template<class T1, class T2> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
   60 | template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
      |                                           ^~~~~~~~
a.cc:193:11: error: redefinition of 'const int MX'
  193 | const int MX = 100005, INF = 1001001001;
      |           ^~
a.cc:62:11: note: 'const int MX' previously defined here
   62 | const int MX = 100005, INF = 1001001001;
      |           ^~
a.cc:193:24: error: redefinition of 'const int INF'
  193 | const int MX = 100005, INF = 1001001001;
      |                        ^~~
a.cc:62:24: note: 'const int INF' previously defined here
   62 | const int MX = 100005, INF = 1001001001;
      |                        ^~~
a.cc:194:10: error: redefinition of 'const ll LINF'
  194 | const ll LINF = 1e18;
      |          ^~~~
a.cc:63:10: note: 'const ll LINF' previously defined here
   63 | const ll LINF = 1e18;
      |          ^~~~
a.cc:195:14: error: redefinition of 'const double eps'
  195 | const double eps = 1e-10;
      |              ^~~
a.cc:64:14: note: 'const double eps' previously defined here
   64 | const double eps = 1e-10;
      |              ^~~
a.cc:197:5: error: redefinition of 'vvi to'
  197 | vvi to;
      |     ^~
a.cc:66:5: note: 'vvi to' previously declared here
   66 | vvi to;
      |     ^~
a.cc:199:5: error: redefinition of 'int main()'
  199 | int main() {
      |     ^~~~
a.cc:68:5: note: 'int main()' previously defined here
   68 | int main() {
      |     ^~~~