Language: C++

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define llpvec vector<pair<ll,ll>>
#define size_(a,b) (a,vector<ll>(b))
#define S 21
/* 
UnionFind：素集合系管理の構造体
issame(x,y): x と y が同じ集合にいるか
unite(x,y): x と y を同じ集合にする
treesize(x): x を含む集合の要素数
weight(x): xでの重みの累積和
diff(x,y): x,yの重みの差
wei_unite(x,y): 重みを考慮したunite(x,y)
*/
 map<ll,bool>used;
struct UnionFind{
 vector<ll>size,parents,diff_weight,rank;
 UnionFind(){}
 UnionFind(ll n){//n個の木を作る
  size.resize(n,1);
  parents.resize(n,0);
  diff_weight.resize(n,0);
  rank.resize(n,0);
  for(ll i=0;i<n;i++)maketree(i);
 }
 void maketree(ll x){
   parents[x]=x;//xの親はx
  }
 bool issame(ll x,ll y){return findroot(x)==findroot(y);}
 bool unite(ll x,ll y){
  x=findroot(x);
  y=findroot(y);
  if(x==y)return false;
  if(rank[x]<rank[y]){
   ll a=x;x=y;y=a;
  }
  if(rank[x]==rank[y])rank[x]++;
  parents[y]=x;
  size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 ll findroot(ll x){//親を探す
  if(x!=parents[x]){
   diff_weight[x]+=diff_weight[parents[x]];
   parents[x]=findroot(parents[x]);
  }
  return parents[x];
 }
 ll treesize(ll x){used[x]=true;return size[findroot(x)];}
 ll weight(ll x){
  findroot(x);
  return diff_weight[x];
 }
 ll diff(ll x,ll y){return abs(weight(y)-weight(x));}
 bool wei_unite(ll x,ll y,ll w){
  w+=weight(x);w-=-weight(y);
  x=findroot(x);y=findroot(y);
  if(x==y)return false;
  if(rank[x]<rank[y]){ll a=x;x=y;y=a;w=-w;}
  if(rank[x]==rank[y])rank[x]++;
  parents[y]=x;
  size[x]+=size[y];
  diff_weight[y]=w;
  return true;
 }
};
/*mod*/const int mod=1e9+7;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗 1*/ll llpow(ll x,ll n){ll ans=1,i;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*n乗 2*/ll modpow(ll x,ll n){ll ans=x,i,tmp=x,t1=1;i=1; while(i<n){if(i*2<n){ans*=ans;ans%=mod;i*=2;}else{t1=1;tmp=x;while(t1*2<n-i){tmp*=tmp;tmp%=mod;t1*=2;}ans*=tmp;ans%=mod;i+=t1;}}return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x){ans*=(x-i);ans%=mod;}return ans;}
/*逆元*/ll inv(ll x){return modpow(x,mod-2);}
/*nCr*/ll ncr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2),c=modpow(fact(r),mod-2);ll ans=a*b;ans%=mod;ans*=c;ans%=mod;return ans;}
/*nPr*/ll npr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2);return (a*b)%mod;}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll i,j;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/}
/*行列のリセット*/void matrst(ll a[S][S]){ll i,j;rep(i,0,S)rep(j,0,S)a[i][j]=0;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll i,j,k;rep(i,0,S)rep(j,0,S)rep(k,0,S){ans[i][j]+=a[i][k]*a[k][j];ans[i][j]%=mod;}matcpy(ans,a);}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll i,j,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S){as[i][j]+=a[i][k]*b[k][j];as[i][j]%=mod;}}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;
 ll l,r,d
 UnionFind u(n);
 rep(i,0,m){
  cin>>l>>r>>d;
  l--;r--;
  if(u.issame(l,r)){
   if(u.diff(l,r)!=d){
    pn;
    return 0;
   }
  }
  else u.wei_unite(l,r,d);
 }
 py;
return 0;}

Compiler output:
a.cc:76:3: error: expected unqualified-id before 'else'
   76 |   else{
      |   ^~~~
a.cc:80:3: error: expected unqualified-id before 'return'
   80 |   return true;
      |   ^~~~~~
a.cc:81:3: error: expected ';' after struct definition
   81 |  }
      |   ^
      |   ;
a.cc: In member function 'bool UnionFind::issame(long long int, long long int)':
a.cc:64:32: error: 'findroot' was not declared in this scope
   64 |  bool issame(ll x,ll y){return findroot(x)==findroot(y);}
      |                                ^~~~~~~~
a.cc: In member function 'bool UnionFind::unite(long long int, long long int)':
a.cc:66:5: error: 'findroot' was not declared in this scope
   66 |   x=findroot(x);
      |     ^~~~~~~~
a.cc: In function 'long long int findroot(long long int)':
a.cc:83:9: error: 'parents' was not declared in this scope
   83 |   if(x!=parents[x]){
      |         ^~~~~~~
a.cc:84:4: error: 'diff_weight' was not declared in this scope
   84 |    diff_weight[x]+=diff_weight[parents[x]];
      |    ^~~~~~~~~~~
a.cc:87:10: error: 'parents' was not declared in this scope
   87 |   return parents[x];
      |          ^~~~~~~
a.cc: In function 'long long int treesize(long long int)':
a.cc:89:44: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   89 |  ll treesize(ll x){used[x]=true;return size[findroot(x)];}
      |                                            ^
a.cc: In function 'long long int weight(long long int)':
a.cc:92:10: error: 'diff_weight' was not declared in this scope
   92 |   return diff_weight[x];
      |          ^~~~~~~~~~~
a.cc: In function 'bool wei_unite(long long int, long long int, long long int)':
a.cc:99:10: error: expected unqualified-id before '[' token
   99 |   if(rank[x]<rank[y]){ll a=x;x=y;y=a;w=-w;}
      |          ^
a.cc:100:10: error: expected unqualified-id before '[' token
  100 |   if(rank[x]==rank[y])rank[x]++;
      |          ^
a.cc:100:30: error: expected initializer before '++' token
  100 |   if(rank[x]==rank[y])rank[x]++;
      |                              ^~
a.cc:100:30: error: expected ';' before '++' token
a.cc:101:3: error: 'parents' was not declared in this scope
  101 |   parents[y]=x;
      |   ^~~~~~~
a.cc:102:7: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
  102 |   size[x]+=size[y];
      |       ^
a.cc:102:16: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
  102 |   size[x]+=size[y];
      |                ^
a.cc:103:3: error: 'diff_weight' was not declared in this scope
  103 |   diff_weight[y]=w;
      |   ^~~~~~~~~~~
a.cc: At global scope:
a.cc:106:1: error: expected declaration before '}' token
  106 | };
      | ^
a.cc: In function 'int main()':
a.cc:131:2: error: expected initializer before 'UnionFind'
  131 |  UnionFind u(n);
      |  ^~~~~~~~~
a.cc:133:14: error: 'd' was not declared in this scope
  133 |   cin>>l>>r>>d;
      |              ^
a.cc:135:6: error: 'u' was not declared in this scope
  135 |   if(u.issame(l,r)){
      |      ^