Language: C++

#include<bits/stdc++.h>
using namespace std;
int par[100010],size[100000];
void init(int n){
  for(int i=0;i<=n;i++)par[i]=i;
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return par[x]==par[y];
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  par[x]=y;
}
int main(){
  int n;cin>>n;
  init(n);
  vector<pair<int,int>>diff(0);
  map<int,int> parity;
  for(int i=0;i<n-1;i++){
    int u,v,w;cin>>u>>v>>w;
    if(w%2==0)unite(u,v);
    else{
      diff.push_back({u,v});
    }
  }
  for(int i=0;i<diff.size();i++){
    diff.at(i).second=root(diff.at(i).second);
    diff.at(i).first=root(diff.at(i).first);
    if(diff.at(i).first>diff.at(i).second)swap(diff.at(i).first,diff.at(i).second)
  }
  sort(diff.begin(),diff.end());
  map[diff.at(0).first]=0;
  for(int i=0;i<diff.size();i++){
    if(parity.find(diff.at(i).first)=parity.end())parity[diff.at(i).second]=parity[diff.at(i).first]+1;
    else if(parity.find(diff.at(i).second)=parity.end())parity[diff.at(i).first]=parity[diff.at(i).second]+1;
  }
  for(int i=1;i<=n;i++){
    if(parity[root(i)]%2){
      cout<<0<<endl;
    }
    else cout<<1<<endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:83: error: expected ';' before '}' token
   34 |     if(diff.at(i).first>diff.at(i).second)swap(diff.at(i).first,diff.at(i).second)
      |                                                                                   ^
      |                                                                                   ;
   35 |   }
      |   ~                                                                                
a.cc:37:11: error: expected ']' before '.' token
   37 |   map[diff.at(0).first]=0;
      |           ^
      |           ]
a.cc:37:7: error: conflicting declaration 'auto diff'
   37 |   map[diff.at(0).first]=0;
      |       ^~~~
a.cc:22:24: note: previous declaration as 'std::vector<std::pair<int, int> > diff'
   22 |   vector<pair<int,int>>diff(0);
      |                        ^~~~
a.cc:39:37: error: could not convert '((* & parity.std::map<int, int>::find(diff.std::vector<std::pair<int, int> >::at(((std::vector<std::pair<int, int> >::size_type)i)).std::pair<int, int>::first)) = parity.std::map<int, int>::end())' from 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} to 'bool'
   39 |     if(parity.find(diff.at(i).first)=parity.end())parity[diff.at(i).second]=parity[diff.at(i).first]+1;
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
      |                                     |
      |                                     std::map<int, int>::iterator {aka std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator}
a.cc:40:43: error: could not convert '((* & parity.std::map<int, int>::find(diff.std::vector<std::pair<int, int> >::at(((std::vector<std::pair<int, int> >::size_type)i)).std::pair<int, int>::second)) = parity.std::map<int, int>::end())' from 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} to 'bool'
   40 |     else if(parity.find(diff.at(i).second)=parity.end())parity[diff.at(i).first]=parity[diff.at(i).second]+1;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
      |                                           |
      |                                           std::map<int, int>::iterator {aka std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator}