Language: C++

#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e10;
const int mod = 1e9+7;

int l[MX];
int r[MX];
int d[MX];
int visit[MX];
vector<vector<pair<int,int>>> mp;
bool ans;
void dfs(int v) {
    int now = visit[v];
    for(auto u:mp[v]) {
       // cout << v<<" "<<u.first<<" " <<u.second << endl;
        
        if(visit[u.first]!=inf && (visit[u.first]!=(now+u.second))) {
        //cout << v<<" "<<u.first<<" " <<u.second<<" "<<visit[u.first]<<" " <<now+u.second << endl;
        
            ans = false;
            return;
        }
        if(visit[u.first]!=inf) continue;
        visit[u.first]=now+u.second;
        //cout << visit[u.first] << endl;
        dfs(u.first);
    }
}
signed main(){
    int n, m;
    cin >>n >> m;
    mp.resize(n);
    rep(i,m) {
        cin >> l[i] >> r[i] >> d[i];
        l[i]--;
        r[i]--;
        mp[l[i]].push_back(make_pair(r[i],d[i]));
        mp[r[i]].push_back(make_pair(l[i],-1*d[i]));
    }
    ans=true;
    rep(i,n) visit[i]=inf;
    visit[l[0]]=0;
    dfs(l[0]);
    rep(i,m) {
        if(visit[i]==inf) {
            dfs(i);
            //cout << "v"<<i << endl;
        }
    }
    //rep(i,n) cout << visit[i] << endl;
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:22:15: error: reference to 'visit' is ambiguous
   22 |     int now = visit[v];
      |               ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:26:12: error: reference to 'visit' is ambiguous
   26 |         if(visit[u.first]!=inf && (visit[u.first]!=(now+u.second))) {
      |            ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:26:36: error: reference to 'visit' is ambiguous
   26 |         if(visit[u.first]!=inf && (visit[u.first]!=(now+u.second))) {
      |                                    ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:32:12: error: reference to 'visit' is ambiguous
   32 |         if(visit[u.first]!=inf) continue;
      |            ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:33:9: error: reference to 'visit' is ambiguous
   33 |         visit[u.first]=now+u.second;
      |         ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:50:14: error: reference to 'visit' is ambiguous
   50 |     rep(i,n) visit[i]=inf;
      |              ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:51:5: error: reference to 'visit' is ambiguous
   51 |     visit[l[0]]=0;
      |     ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~
a.cc:54:12: error: reference to 'visit' is ambiguous
   54 |         if(visit[i]==inf) {
      |            ^~~~~
/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:18:5: note:                 'long long int visit [1000000]'
   18 | int visit[MX];
      |     ^~~~~