Language: C++

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e5+100;
vector<PII> ad[sz];
ll n;
ll ans[sz];
ll len[sz];
void DFS(ll p,ll parent,ll sum)
{
    len[p]=sum;
    for(auto xx: ad[p])
    {
        if(xx.s != parent){
            if(((sum+xx.f) & 1ll) == (len[p] &1ll) ){
                ans[xx.s]=ans[p];
            }
            else{
                ans[xx.s]=(ans[p] ^ 1ll );
            }
            DFS(xx.s,p,sum+xx.f);
        }
    }
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        for(i=0;i<=n;i++) ad[i].clear();
        for(i=1;i<n;i++){
            cin>>p>>q>>x;
            ad[p].pb({x,q});
            ad[q].pb({x,p});
        }
 
        ans[1]=0;
        DFS(1,-1,0);
        for(i=1;i<=n;i++){
            cout<<ans[i]<<endl;
        }
    }
 
 
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e5+100;
vector<PII> ad[sz];
ll n;
ll ans[sz];
ll len[sz];
void DFS(ll p,ll parent,ll sum)
{
    len[p]=sum;
    for(auto xx: ad[p])
    {
        if(xx.s != parent){
            if(((sum+xx.f) & 1ll) == (len[p] &1ll) ){
                ans[xx.s]=ans[p];
            }
            else{
                ans[xx.s]=(ans[p] ^ 1ll );
            }
            DFS(xx.s,p,sum+xx.f);
        }
    }
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        for(i=0;i<=n;i++) ad[i].clear();
        for(i=1;i<n;i++){
            cin>>p>>q>>x;
            ad[p].pb({x,q});
            ad[q].pb({x,p});
        }

        ans[1]=0;
        DFS(1,-1,0);
        for(i=1;i<=n;i++){
            cout<<ans[i]<<endl;
        }
    }


}


Compiler output:
a.cc:94:5: error: redefinition of 'int dx8 []'
   94 | int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
      |     ^~~
a.cc:18:5: note: 'int dx8 [8]' previously defined here
   18 | int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
      |     ^~~
a.cc:95:5: error: redefinition of 'int dy8 []'
   95 | int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
      |     ^~~
a.cc:19:5: note: 'int dy8 [8]' previously defined here
   19 | int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
      |     ^~~
a.cc:96:5: error: redefinition of 'int dx4 []'
   96 | int dx4[] = {0, 0, 1, -1};
      |     ^~~
a.cc:20:5: note: 'int dx4 [4]' previously defined here
   20 | int dx4[] = {0, 0, 1, -1};
      |     ^~~
a.cc:97:5: error: redefinition of 'int dy4 []'
   97 | int dy4[] = {1, -1, 0, 0};
      |     ^~~
a.cc:21:5: note: 'int dy4 [4]' previously defined here
   21 | int dy4[] = {1, -1, 0, 0};
      |     ^~~
a.cc:100:5: error: redefinition of 'int Set(int, int)'
  100 | int Set(int N,int pos){return N=N | (1<<pos);}
      |     ^~~
a.cc:24:5: note: 'int Set(int, int)' previously defined here
   24 | int Set(int N,int pos){return N=N | (1<<pos);}
      |     ^~~
a.cc:101:5: error: redefinition of 'int reset(int, int)'
  101 | int reset(int N,int pos){return N= N & ~(1<<pos);}
      |     ^~~~~
a.cc:25:5: note: 'int reset(int, int)' previously defined here
   25 | int reset(int N,int pos){return N= N & ~(1<<pos);}
      |     ^~~~~
a.cc:102:6: error: redefinition of 'bool check(int, int)'
  102 | bool check(int N,int pos){return (bool)(N & (1<<pos));}
      |      ^~~~~
a.cc:26:6: note: 'bool check(int, int)' previously defined here
   26 | bool check(int N,int pos){return (bool)(N & (1<<pos));}
      |      ^~~~~
a.cc:103:11: error: redefinition of 'const int max'
  103 | const int max=1e9+100;
      |           ^~~
a.cc:27:11: note: 'const int max' previously defined here
   27 | const int max=1e9+100;
      |           ^~~
a.cc:104:11: error: redefinition of 'const long long int MAX'
  104 | const ll  MAX=1e18+500;
      |           ^~~
a.cc:28:11: note: 'const long long int MAX' previously defined here
   28 | const ll  MAX=1e18+500;
      |           ^~~
a.cc:105:11: error: redefinition of 'const int sz'
  105 | const int sz=1e5+100;
      |           ^~
a.cc:29:11: note: 'const int sz' previously defined here
   29 | const int sz=1e5+100;
      |           ^~
a.cc:106:13: error: redefinition of 'std::vector<std::pair<long long int, long long int> > ad [100100]'
  106 | vector<PII> ad[sz];
      |             ^~
a.cc:30:13: note: 'std::vector<std::pair<long long int, long long int> > ad [100100]' previously declared here
   30 | vector<PII> ad[sz];
      |             ^~
a.cc:107:4: error: redefinition of 'long long int n'
  107 | ll n;
      |    ^
a.cc:31:4: note: 'long long int n' previously declared here
   31 | ll n;
      |    ^
a.cc:108:4: error: redefinition of 'long long int ans [100100]'
  108 | ll ans[sz];
      |    ^~~
a.cc:32:4: note: 'long long int ans [100100]' previously declared here
   32 | ll ans[sz];
      |    ^~~
a.cc:109:4: error: redefinition of 'long long int len [100100]'
  109 | ll len[sz];
      |    ^~~
a.cc:33:4: note: 'long long int len [100100]' previously declared here
   33 | ll len[sz];
      |    ^~~
a.cc:110:6: error: redefinition of 'void DFS(long long int, long long int, long long int)'
  110 | void DFS(ll p,ll parent,ll sum)
      |      ^~~
a.cc:34:6: note: 'void DFS(long long int, long long int, long long int)' previously defined here
   34 | void DFS(ll p,ll parent,ll sum)
      |      ^~~
a.cc:126:5: error: redefinition of 'int main()'
  126 | int main()
      |     ^~~~
a.cc:50:5: note: 'int main()' previously defined here
   50 | int main()
      |     ^~~~