Language: C++

/**
*	created: 27.08.2020 16:33:15
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// ポテンシャル付きUnionFind
struct UnionFind {
    vector<int> par, wei;
    UnionFind(int n) : par(n,-1), wei(n,0) {}
    int root(int x) {
        if (par[x] < 0) return x;
        else {wei[x] += wei[par[x]]; return par[x] = root(par[x]);}
    }
    bool unite(int x, int y, int w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) {swap(x,y); w = -w;}
        par[x] += par[y]; par[y] = x;
        wei[y] = w;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);}
    int weight(int x) {root(x); return wei[x];}
    int size(int x) {return -par[root(x)];}
    int diff(int x, int y) {return weight(y) - weight(x);}
};

template<class Abel> struct UnionFind2 {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

signed main() {
    int n, m; cin >> n >> m;
    UnionFind2 uf(n);
    rep(i,m) {
        int l, r, d; cin >> l >> r >> d;
        l--, r--;
        if (uf.issame(l,r)) {
            int diff = uf.diff(l,r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else uf.merge(l,r,d);
    }
    cout << "Yes" << endl;
    return 0;
}

Compiler output:
a.cc:11:13: error: expected unqualified-id before 'long'
   11 | #define int long long
      |             ^~~~
a.cc:55:15: note: in expansion of macro 'int'
   55 |     UnionFind(int n = 1, Abel SUM_UNITY = 0) {
      |               ^~~
a.cc:55:15: error: expected ')' before 'long'
   55 |     UnionFind(int n = 1, Abel SUM_UNITY = 0) {
      |              ~^
      |               )
a.cc: In function 'int main()':
a.cc:102:20: error: class template argument deduction failed:
  102 |     UnionFind2 uf(n);
      |                    ^
a.cc:102:20: error: no matching function for call to 'UnionFind2(long long int&)'
a.cc:50:29: note: candidate: 'template<class Abel> UnionFind2()-> UnionFind2<Abel>'
   50 | template<class Abel> struct UnionFind2 {
      |                             ^~~~~~~~~~
a.cc:50:29: note:   candidate expects 0 arguments, 1 provided
a.cc:50:29: note: candidate: 'template<class Abel> UnionFind2(UnionFind2<Abel>)-> UnionFind2<Abel>'
a.cc:50:29: note:   template argument deduction/substitution failed:
a.cc:102:20: note:   mismatched types 'UnionFind2<Abel>' and 'long long int'
  102 |     UnionFind2 uf(n);
      |                    ^