Language: C++

#define NDEBUG
#include <cassert>
#include <cstdint>
#include <functional>
#include <tuple>
#include <vector>

template <typename Abelian> class PotentializedUnionFindTree {

public:
	using value_type = Abelian;
	using reference = value_type &;
	using const_reference = const value_type &;
	using size_type = std::uint_fast32_t;

private:
	using F = std::function<value_type(const_reference, const_reference)>;
	using G = std::function<value_type(const_reference)>;
	const F f;
	const G g;
	const value_type neutral_;
	std::vector<std::tuple<bool, size_type, value_type>> tree;

public:
	PotentializedUnionFindTree(const size_type size,
		const_reference neutral = value_type(),
		const F &f = std::plus<value_type>(),
		const G &g = std::negate<value_type>())
		: f(f), g(g), neutral_(neutral),
		tree(size, std::forward_as_tuple(1, 1, neutral_)) {}
	size_type find(const size_type x) {
		assert(x < tree.size());
		if (std::get<0>(tree[x]))
			return x;
		const size_type t = std::get<1>(tree[x]);
		std::get<1>(tree[x]) = find(t);
		std::get<2>(tree[x]) = f(std::get<2>(tree[t]), std::get<2>(tree[x]));
		return std::get<1>(tree[x]);
	}
	value_type potential(const size_type x) {
		assert(x < tree.size());
		find(x);
		return std::get<2>(tree[x]);
	}
	value_type diff(const size_type x, const size_type y) {
		assert(x < tree.size());
		assert(y < tree.size());
		return f(potential(y), g(potential(x)));
	}
	bool unite(size_type x, size_type y, value_type d) {
		assert(x < tree.size());
		assert(y < tree.size());
		d = f(d, diff(y, x));
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (std::get<1>(tree[x]) < std::get<1>(tree[y]))
			std::swap(x, y), d = g(d);
		std::get<1>(tree[x]) += std::get<1>(tree[y]);
		tree[y] = std::forward_as_tuple(0, x, d);
		return true;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < tree.size());
		assert(y < tree.size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < tree.size());
		return std::get<1>(tree[find(x)]);
	}
};
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

const char *yes(bool c) { return c ? "yes" : "no"; }
const char *Yes(bool c) { return c ? "Yes" : "No"; }
const char *YES(bool c) { return c ? "YES" : "NO"; }
const char *pos(bool c) { return c ? "possible" : "impossible"; }
const char *Pos(bool c) { return c ? "Possible" : "Impossible"; }
const char *POS(bool c) { return c ? "POSSIBLE" : "IMPOSSIBLE"; }
template<class T>bool bmaxi(T&a, const T&b) { if (b<a)return 0;a = b;return 1; }
template<class T>bool bmini(T&a, const T&b) { if (a<b)return 0;a = b;return 1; }
template<class T>bool nmaxi(T&a, const T&b) { if (a<b) { a = b;return 1; }return 0; }
template<class T>bool nmini(T&a, const T&b) { if (b<a) { a = b;return 1; }return 0; }
template<typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value>::type
{
	d = 0;int c = fgetc(stdin);bool f = 0;while (c<'0' || '9'<c) { if (c == '-')f = 1;c = fgetc(stdin); }
	while (c != ' '&&c != '\n') { d = d * 10 + c - '0';c = fgetc(stdin); }if (f)d = -d;
}
template<typename T>auto scan(T&d)->typename std::enable_if<!std::is_signed<T>::value>::type
{
	d = 0;int c = fgetc(stdin);while (c == ' ' || c == '\n')c = fgetc(stdin);
	while (c != ' '&&c != '\n') { d = d * 10 + c - '0';c = fgetc(stdin); }
}
void scan(char&d) { d = fgetc(stdin);while (d == ' ' || d == '\n')d = fgetc(stdin); }
void scan(double&d) { scanf("%lf", &d); }void scan(std::string&d) {
	d.clear();int c = fgetc(stdin);
	while (c == ' ' || c == '\n')c = fgetc(stdin);while (c != ' '&&c != '\n') { d.push_back(c);c = fgetc(stdin); }
}
template<typename F, typename...R>void scan(F&f, R&...r) { scan(f);scan(r...); }
template<typename T>T input() { T d;scan(d);return d; }
template <typename T>auto print(T d)->typename std::enable_if<std::is_signed<T>::value>::type
{
	static int c[20];int i = 0;bool f = 0;if (d<0) { f = 1;d = -d; }while (d) { c[i++] = d % 10;d /= 10; }
	if (!i)c[i++] = 0;if (f)fputc('-', stdout);while (i--)fputc(c[i] + '0', stdout);
}
template<typename T>auto print(T d)->typename std::enable_if<!std::is_signed<T>::value>::type
{
	static int c[20];int i = 0;while (d) { c[i++] = d % 10;d /= 10; }
	if (!i)c[i++] = 0;while (i--)fputc(c[i] + '0', stdout);
}
template<>void print<char>(char d) { fputc(d, stdout); }
template<>void print<double>(double d) { printf("%f", d); }
template<>void print<char *>(char *c) { while (*c != '\0')fputc(*(c++), stdout); }void print() {}
template<typename F, typename...R>void print(F f, R...r) { print(f);print(r...); }
template<typename...R>void println(R...r) { print(r...);fputc('\n', stdout); }
template<typename...R>int END(R...r) { println(r...);return 0; }

#include<iostream>
int main(void) {
	uint32 n, m;
	scan(n, m);
	PotentializedUnionFindTree<int32> T(n, 0);
	while (m--) {
		uint32 l, r;int32 d;
		scan(l, r, d);
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) return END("No");
		}
	}
	println("Yes");
	return 0;
}

Compiler output:
a.cc: In instantiation of 'typename std::enable_if<(! std::is_signed<_Tp>::value)>::type print(T) [with T = const char*; typename std::enable_if<(! std::is_signed<_Tp>::value)>::type = void]':
a.cc:149:50:   required from 'void println(R ...) [with R = {const char*}]'
  149 | template<typename...R>void println(R...r) { print(r...);fputc('\n', stdout); }
      |                                             ~~~~~^~~~~~
a.cc:165:9:   required from here
  165 |         println("Yes");
      |         ~~~~~~~^~~~~~~
a.cc:142:59: error: invalid operands of types 'const char*' and 'int' to binary 'operator%'
  142 |         static int c[20];int i = 0;while (d) { c[i++] = d % 10;d /= 10; }
      |                                                         ~~^~~~
a.cc:142:66: error: invalid operands of types 'const char*' and 'int' to binary 'operator/'
  142 |         static int c[20];int i = 0;while (d) { c[i++] = d % 10;d /= 10; }
      |                                                                ~~^~~~~
a.cc:142:66: note:   in evaluation of 'operator/=(const char*, int)'