Language: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#define inf -2147483647
using namespace std;
struct info
{
    int l,r,d;
}s[400005];
int n,m;
int flag = 1;
int dis[100005],visited[100005];
int first[400005],next[400005];
void dfs(int t)
{
    if(!flag)return;
    int k = first[t];
    while(k != -1)
    {
        if(!flag)return;
        if(!visited[s[k].r])
        {
            dis[s[k].r] = dis[s[k].l] + s[k].d;
            visited[s[k].r] = 1;
            dfs(s[k].r);
        }
        else if(s[k].d != dis[s[k].r] - dis[s[k].l])
        {
            flag = 0;
            return;
        }
        k = next[k];
    }
}
int main()
{
    cin>>n>>m;
    memset(first,-1,sizeof(first));
    for(int i = 0;i < m;i ++)
    {
        cin>>s[i].l>>s[i].r>>s[i].d;
        next[i] = first[s[i].l];
        first[s[i].l] = i;
        s[i + m].r = s[i].l;
        s[i + m].l = s[i].r;
        s[i + m].d = -s[i].d;
        next[i + m] = first[s[i + m].l];
        first[s[i + m].l] = i + m;
    }
    for(int i = 1;i <= n;i ++)
    {
        if(!visited[i])
        {
            visited[i] = 1;
            memset(dis,0,sizeof(dis));
            dfs(i);
        }
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:36:13: error: reference to 'next' is ambiguous
   36 |         k = next[k];
      |             ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:17:19: note:                 'int next [400005]'
   17 | int first[400005],next[400005];
      |                   ^~~~
a.cc: In function 'int main()':
a.cc:46:9: error: reference to 'next' is ambiguous
   46 |         next[i] = first[s[i].l];
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:17:19: note:                 'int next [400005]'
   17 | int first[400005],next[400005];
      |                   ^~~~
a.cc:51:9: error: reference to 'next' is ambiguous
   51 |         next[i + m] = first[s[i + m].l];
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:17:19: note:                 'int next [400005]'
   17 | int first[400005],next[400005];
      |                   ^~~~