Language: C++

#include<iostream>
#include<cstring>
#include<queue>
#include<stdlib.h>
using namespace std;
const int maxn=1000000;
struct eg{
       int dot,w;
       };
eg E[maxn];
int head[maxn],next[maxn];
int d[maxn],cnt[maxn];
int id=0,n,m;
void add(int x,int y,int z)
{
     E[++id].dot=y;
     E[id].w=x;
     next[id]=head[x];
     head[x]=id;
}
int n,m;
void sf()
{
     for(int s=1;s<=n;s++)
     {
         memset(d,0x3f,sizeof(d));
         memset(v,true,sizeof(v));
         queue<int> Q;
         d[s]=0;
         Q.push(s);
         v[s]=false;
         while(Q.size())
         {
              int x=Q.front();
              Q.pop();
              v[x]=true;
              for(int i=head[x];i;i=next[i])
              {
                  int y=E[i].y;
                  if(d[y]>d[x]+E[i].w)
                  {
                      d[y]=d[x]+E[i].w;
                      if(cnt[y]++
                      
         
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(z>n+1)
        {
           cout<<"No"<<endl;
           return 0;
        }
        add(x,y,z); 
        add(y,x,-z);
    }
    topo();
    if(t<n)
    {
       cout<<"No"<<endl;
       return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}   

Compiler output:
a.cc: In function 'void add(int, int, int)':
a.cc:18:6: error: reference to 'next' is ambiguous
   18 |      next[id]=head[x];
      |      ^~~~
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:11:16: note:                 'int next [1000000]'
   11 | int head[maxn],next[maxn];
      |                ^~~~
a.cc: At global scope:
a.cc:21:5: error: redefinition of 'int n'
   21 | int n,m;
      |     ^
a.cc:13:10: note: 'int n' previously declared here
   13 | int id=0,n,m;
      |          ^
a.cc:21:7: error: redefinition of 'int m'
   21 | int n,m;
      |       ^
a.cc:13:12: note: 'int m' previously declared here
   13 | int id=0,n,m;
      |            ^
a.cc: In function 'void sf()':
a.cc:27:17: error: 'v' was not declared in this scope
   27 |          memset(v,true,sizeof(v));
      |                 ^
a.cc:37:37: error: reference to 'next' is ambiguous
   37 |               for(int i=head[x];i;i=next[i])
      |                                     ^~~~
/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:11:16: note:                 'int next [1000000]'
   11 | int head[maxn],next[maxn];
      |                ^~~~
a.cc:39:30: error: 'struct eg' has no member named 'y'
   39 |                   int y=E[i].y;
      |                              ^
a.cc:43:34: error: expected ')' before '}' token
   43 |                       if(cnt[y]++
      |                         ~        ^
      |                                  )
......
   46 | }
      | ~                                 
a.cc:46:1: error: expected primary-expression before '}' token
   46 | }
      | ^
a.cc:47:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   47 | int main()
      |         ^~
a.cc:47:9: note: remove parentheses to default-initialize a variable
   47 | int main()
      |         ^~
      |         --
a.cc:47:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:48:1: error: a function-definition is not allowed here before '{' token
   48 | {
      | ^
a.cc:70:2: error: expected '}' at end of input
   70 | }
      |  ^
a.cc:38:15: note: to match this '{'
   38 |               {
      |               ^
a.cc:70:2: error: expected '}' at end of input
   70 | }
      |  ^
a.cc:33:10: note: to match this '{'
   33 |          {
      |          ^
a.cc:70:2: error: expected '}' at end of input
   70 | }
      |  ^
a.cc:25:6: note: to match this '{'
   25 |      {
      |      ^
a.cc:70:2: error: expected '}' at end of input
   70 | }
      |  ^
a.cc:23:1: note: to match this '{'
   23 | {
      | ^