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:23: error: class template argument deduction failed:
   37 |   map(diff.at(0).first)=0;
      |                       ^
a.cc:37:23: error: no matching function for call to 'map(int&)'
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:302:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator, const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  302 |         map(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:302:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:285:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  285 |         map(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:285:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:268:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  268 |         map(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:268:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:262:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::initializer_list<std::pair<const _Key, _Val> >, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  262 |       map(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:262:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:256:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Allocator>&&, std::__type_identity_t<_Alloc>&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  256 |       map(map&& __m, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:256:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:252:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const std::map<_Key, _Tp, _Compare, _Allocator>&, std::__type_identity_t<_Alloc>&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  252 |       map(const map& __m, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:252:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:248:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  248 |       map(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:248:7: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   couldn't deduce template parameter '_Key'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:240:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::initializer_list<std::pair<const _Key, _Val> >, const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  240 |       map(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:240:7: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   mismatched types 'std::initializer_list<std::pair<const _Key, _Val> >' and 'int'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:227:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Allocator>&&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  227 |       map(map&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:227:7: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   mismatched types 'std::map<_Key, _Tp, _Compare, _Allocator>' and 'int'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:219:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const std::map<_Key, _Tp, _Compare, _Allocator>&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  219 |       map(const map&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:219:7: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   mismatched types 'const std::map<_Key, _Tp, _Compare, _Allocator>' and 'int'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:206:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  206 |       map(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:206:7: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   couldn't deduce template parameter '_Key'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:197:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map()-> std::map<_Key, _Tp, _Compare, _Alloc>'
  197 |       map() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:197:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Alloc>)-> std::map<_Key, _Tp, _Compare, _Alloc>'
  102 |     class map
      |           ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   mismatched types 'std::map<_Key, _Tp, _Compare, _Alloc>' and 'int'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:1495:5: note: candidate: 'template<class _Key, class _Tp, class _Allocator, class> std::map(initializer_list<pair<_T1, _T2> >, _Allocator)-> map<_Key, _Tp, less<_Key>, _Allocator>'
 1495 |     map(initializer_list<pair<_Key, _Tp>>, _Allocator)
      |     ^~~
/usr/include/c++/14/bits/stl_map.h:1495:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:1489:5: note: candidate: 'template<class _InputIterator, class _Allocator, class, class> std::map(_InputIterator, _InputIterator, _Allocator)-> map<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type, typename iterator_traits< <template-parameter-1-1> >::value_type::second_type, less<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type>, _Allocator>'
 1489 |     map(_InputIterator, _InputIterator, _Allocator)
      |     ^~~
/usr/include/c++/14/bits/stl_map.h:1489:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:1482:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Allocator, class, class> std::map(initializer_list<pair<_T1, _T2> >, _Compare, _Allocator)-> map<_Key, _Tp, _Compare, _Allocator>'
 1482 |     map(initializer_list<pair<_Key, _Tp>>,
      |     ^~~
/usr/include/c++/14/bits/stl_map.h:1482:5: note:   template argument deduction/substitution failed:
a.cc:37:23: note:   mismatched types 'std::initializer_list<std::pair<_T1, _T2> >' and 'int'
   37 |   map(diff.at(0).first)=0;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:1473:5: note: candidate: 'template<class _InputIterator, class _Compare, class _Allocator, class, class, class> std::map(_InputIterator, _InputIterator, _Compare, _Allocator)-> map<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type, typename iterator_traits< <template-parameter-1-1> >::value_type::second_type, _Compare, _Allocator>'
 1473 |     map(_InputIterator, _InputIterator,
      |     ^~~
/usr/include/c++/14/bits/stl_map.h:1473:5: note:   candidate expects 2 arguments, 1 provided
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::p