Language: C++

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

template <typename T>
struct WeightedUnionFind {
	LL n;
	T d;
	vector<Int> r, p;
	vector<T> ws;
	WeightedUnionFind() {}
	WeightedUnionFind(LL sz, T d_) :
		n(sz), d(d_), r(n, 1), p(n), ws(n, d) {
		iota(p.begin(), p.end(), 0);
	}
	LL find(LL x) {
		if (x == p[x]) {
			return x;
		}
		else {
			Int t = find(p[x]);
			ws[x] += ws[p[x]];
			return p[x] = t;
		}
	}
	T weight(LL x) {
		find(x);
		return ws[x];
	}
	bool same(LL x, LL y) {
		return find(x) == find(y);
	}
	void unite(LL x, LL y, T w) {
		w += weight(x);
		w -= weight(y);
		x = find(x); y = find(y);
		if (x == y) return;
		if (r[x]<r[y]) swap(x, y), w = -w;
		r[x] += r[y];
		p[y] = x;
		ws[y] = w;
	}
	T diff(LL x, LL y) {
		return weight(y) - weight(x);
	}
};

int main() {
	LL n, m;
	cin >> n >> m;
	WeightedUnionFind<LL> wuf(n + 1, 0);
	for (LL i = 0; i<m; i++) {
		LL l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		if (wuf.same(l, r)) {
			if (wuf.diff(l, r) != d) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			wuf.unite(l, r, d);
		}
	}
	cout << "Yes" << endl;
}

Compiler output:
a.cc:44:16: error: 'Int' was not declared in this scope; did you mean 'int'?
   44 |         vector<Int> r, p;
      |                ^~~
      |                int
a.cc:44:19: error: template argument 1 is invalid
   44 |         vector<Int> r, p;
      |                   ^
a.cc:44:19: error: template argument 2 is invalid
a.cc: In constructor 'WeightedUnionFind<T>::WeightedUnionFind(LL, T)':
a.cc:49:24: error: request for member 'begin' in '((WeightedUnionFind<T>*)this)->WeightedUnionFind<T>::p', which is of non-class type 'int'
   49 |                 iota(p.begin(), p.end(), 0);
      |                        ^~~~~
a.cc:49:35: error: request for member 'end' in '((WeightedUnionFind<T>*)this)->WeightedUnionFind<T>::p', which is of non-class type 'int'
   49 |                 iota(p.begin(), p.end(), 0);
      |                                   ^~~
a.cc: In member function 'LL WeightedUnionFind<T>::find(LL)':
a.cc:52:27: error: invalid types 'int[LL {aka long long int}]' for array subscript
   52 |                 if (x == p[x]) {
      |                           ^
a.cc:56:25: error: 'Int' was not declared in this scope; did you mean 'int'?
   56 |                         Int t = find(p[x]);
      |                         ^~~
      |                         int
a.cc:57:38: error: invalid types 'int[LL {aka long long int}]' for array subscript
   57 |                         ws[x] += ws[p[x]];
      |                                      ^
a.cc:58:33: error: invalid types 'int[LL {aka long long int}]' for array subscript
   58 |                         return p[x] = t;
      |                                 ^
a.cc:58:39: error: 't' was not declared in this scope
   58 |                         return p[x] = t;
      |                                       ^
a.cc: In member function 'void WeightedUnionFind<T>::unite(LL, LL, T)':
a.cc:73:22: error: invalid types 'int[LL {aka long long int}]' for array subscript
   73 |                 if (r[x]<r[y]) swap(x, y), w = -w;
      |                      ^
a.cc:73:27: error: invalid types 'int[LL {aka long long int}]' for array subscript
   73 |                 if (r[x]<r[y]) swap(x, y), w = -w;
      |                           ^
a.cc:74:18: error: invalid types 'int[LL {aka long long int}]' for array subscript
   74 |                 r[x] += r[y];
      |                  ^
a.cc:74:26: error: invalid types 'int[LL {aka long long int}]' for array subscript
   74 |                 r[x] += r[y];
      |                          ^
a.cc:75:18: error: invalid types 'int[LL {aka long long int}]' for array subscript
   75 |                 p[y] = x;
      |                  ^
a.cc: In instantiation of 'WeightedUnionFind<T>::WeightedUnionFind(LL, T) [with T = long long int; LL = long long int]':
a.cc:86:36:   required from here
   86 |         WeightedUnionFind<LL> wuf(n + 1, 0);
      |                                           ^
a.cc:48:31: error: expression list treated as compound expression in mem-initializer [-fpermissive]
   48 |                 n(sz), d(d_), r(n, 1), p(n), ws(n, d) {
      |                               ^~~~~~~