Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

struct edge {
    int to;
    int cost;
};

int N, M; 
vector<vector<edge>> g;
vector<bool> visit; 
vector<int> d;

bool dfs(int v) {  
    visit[v] = true;
    for (auto e : g[v]) {
        if (visit[e.to]) {
            if (d[e.to] != d[v] + e.cost) return false;
        }
        else {
            d[e.to] = d[v] + e.cost;
            return dfs(e.to);
        }
    }
    return true;
}

void solve() {
    cin >> N >> M;
    g.resize(N);
    for (int i = 0; i < M; i++) {
        int L, R, D; cin >> L >> R >> D;
        L--; R--;
        g[L].push_back({R, D});
        g[R].push_back({L, -D});
    }

    visit.resize(N);
    d.resize(N);
    for (int i = 0; i < N; i++) {
        if (!visit[i]) {
            d[i] = 0;
            if (!dfs(i)) {
                cout << "No" << '\n';
                return;
            }
        }
    }

    cout << "Yes" << '\n';
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Compiler output:
a.cc: In function 'bool dfs(int)':
a.cc:38:5: error: reference to 'visit' is ambiguous
   38 |     visit[v] = true;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:2:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:34:14: note:                 'std::vector<bool> visit'
   34 | vector<bool> visit;
      |              ^~~~~
a.cc:40:13: error: reference to 'visit' is ambiguous
   40 |         if (visit[e.to]) {
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:34:14: note:                 'std::vector<bool> visit'
   34 | vector<bool> visit;
      |              ^~~~~
a.cc: In function 'void solve()':
a.cc:61:5: error: reference to 'visit' is ambiguous
   61 |     visit.resize(N);
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:34:14: note:                 'std::vector<bool> visit'
   34 | vector<bool> visit;
      |              ^~~~~
a.cc:64:14: error: reference to 'visit' is ambiguous
   64 |         if (!visit[i]) {
      |              ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:34:14: note:                 'std::vector<bool> visit'
   34 | vector<bool> visit;
      |              ^~~~~