Language: C++

#include<iostream>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

  int par[1000000];
  int rank[1000000];

  void init(int n){
    for(int i=0; i<=n; ++i){
      par[i]=i;
      rank[i]=0;
    }
  }
  
  int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
  }
  
  void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(rank[x]<rank[y]) par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  
  bool same(int x, int y) return find(x)==find(y);
  

int main(){
  int N;
  cin>>N;
  init(N);
  
  for(int i=1; i<N; ++i){
    int A,B,C;
    cin>>A>>B>>C;
    if(C%2==0) unite(A,B);
  }
  
  for(int i=1; i<=N; ++i){
    if(same(i,1)==true) cout<<"1"<<endl;:
    else cout<<"0"<<endl;
  }
  
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:15:7: error: reference to 'rank' is ambiguous
   15 |       rank[i]=0;
      |       ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:28:8: error: reference to 'rank' is ambiguous
   28 |     if(rank[x]<rank[y]) par[x]=y;
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc:28:16: error: reference to 'rank' is ambiguous
   28 |     if(rank[x]<rank[y]) par[x]=y;
      |                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc:31:10: error: reference to 'rank' is ambiguous
   31 |       if(rank[x]==rank[y]) rank[x]++;
      |          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc:31:19: error: reference to 'rank' is ambiguous
   31 |       if(rank[x]==rank[y]) rank[x]++;
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc:31:28: error: reference to 'rank' is ambiguous
   31 |       if(rank[x]==rank[y]) rank[x]++;
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:7: note:                 'int rank [1000000]'
   10 |   int rank[1000000];
      |       ^~~~
a.cc: In function 'bool same(int, int)':
a.cc:35:27: error: named return values are no longer supported
   35 |   bool same(int x, int y) return find(x)==find(y);
      |                           ^~~~~~
a.cc:50:41: error: expected primary-expression before ':' token
   50 |     if(same(i,1)==true) cout<<"1"<<endl;:
      |                                         ^
a.cc:54:1: warning: no return statement in function returning non-void [-Wreturn-type]
   54 | }
      | ^