Language: C++

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
void SPFA();
queue<int> q;
int dis[1005],a[1005][1005],n,m,st,en,time[1005];
bool flag;
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        flag=1;
        memset(a,0,sizeof(a));
        memset(dis,0,sizeof(dis));
        memset(time, 0, sizeof(time));
        for(int j=0; j<m; ++j)
        {
            int a1,a2,a3;
            scanf("%d%d%d",&a1,&a2,&a3);
            if(a3 > a[a1][a2])
            {
                a[a1][a2]=a3;
            }
        }

        st = 1;
        SPFA();

        if(!flag)
            cout<<"inf"<<endl;
        else
        {
            cout << dis[n] << endl;
        }
    }
    return 0;
}
void SPFA()
{
    dis[st]=0;
    q.push(st);
    while(!q.empty())
    {
        int i=q.front();
        q.pop();
        for(int i1=1; i1<=n; ++i1)
        {
            if(dis[i1]<dis[i]+a[i][i1] && a[i][i1])
            {
                dis[i1]=dis[i]+a[i][i1];
                q.push(i1);
                time[i1]++;
            }
            if(time[i1]>n)
            {
                flag=0;
                while(!q.empty())
                    q.pop();
                break;
            }
        }
    }
}


Compiler output:
a.cc:10:48: error: 'int time [1005]' redeclared as different kind of entity
   10 | int dis[1005],a[1005][1005],n,m,st,en,time[1005];
      |                                                ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:19:32: error: ISO C++ forbids applying 'sizeof' to an expression of function type [-fpermissive]
   19 |         memset(time, 0, sizeof(time));
      |                               ~^~~~~
a.cc:19:16: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'void*' [-fpermissive]
   19 |         memset(time, 0, sizeof(time));
      |                ^~~~
      |                |
      |                time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
In file included from /usr/include/c++/14/cstring:43,
                 from a.cc:3:
/usr/include/string.h:61:28: note:   initializing argument 1 of 'void* memset(void*, int, size_t)'
   61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
      |                      ~~~~~~^~~
a.cc: In function 'void SPFA()':
a.cc:56:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |                 time[i1]++;
      |                        ^
a.cc:56:24: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   56 |                 time[i1]++;
      |                 ~~~~~~~^
a.cc:56:24: error: lvalue required as increment operand
   56 |                 time[i1]++;
      |                        ^
a.cc:58:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             if(time[i1]>n)
      |                       ^
a.cc:58:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   58 |             if(time[i1]>n)
      |                ~~~~~~~~^~