Language: C++

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e15;
const ll MOD = 1e9 + 7;

// O(|V||E|)
class Graph {
private:
  ll V; // 0index
  vector<pair<ll, pll>> edges;
  vector<bool> hasNegativeCycles;
  vector<ll> dist;

public:
  Graph(ll V);
  void addEdge(ll u, ll v, ll w);
  void bellmanFord(ll src);
  ll getDistance(ll n);
  bool hasNegativeCycle(ll n);
};
Graph::Graph(ll V) {
  this->V = V;
  this->dist = vector<ll>(this->V, INF);
  this->hasNegativeCycles = vector<bool>(this->V, false);
}
void Graph::addEdge(ll u, ll v, ll w) { edges.push_back({w, {u, v}}); }
void Graph::bellmanFord(ll src) {
  this->dist[src] = 0;
  vector<pair<ll, pair<ll, ll>>>::iterator it;

  for (ll i = 0; i < this->V - 1; i++) {
    for (it = edges.begin(); it != edges.end(); ++it) {
      ll u = it->second.first;
      ll v = it->second.second;
      ll w = it->first;
      if (this->dist[u] + w < this->dist[v]) {
        this->dist[v] = this->dist[u] + w;
      }
    }
  }

  for (it = edges.begin(); it != edges.end(); ++it) {
    ll u = it->second.first;
    ll v = it->second.second;
    ll w = it->first;
    if (this->dist[u] + w < this->dist[v]) {
      this->hasNegativeCycles[v] = true;
    }
    if (this->hasNegativeCycles[u] == true) {
      this->hasNegativeCycles[v] = true;
    }
  }
}
ll Graph::getDistance(ll n) { return this->dist[n]; }
bool Graph::hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; }

void solve(long long N, long long M, std::vector<long long> a,
           std::vector<long long> b, std::vector<long long> c) {
  Graph g(N);
  rep(m, 0, M) { g.addEdge(a[m] - 1, b[m] - 1, -c[m]); }
  g.bellmanFord(0);

  if (!g.hasNegativeCycle()) {
    print(-g.getDistance(N - 1));
  } else {
    print("inf");
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(a), std::move(b), std::move(c));
  return 0;
}


Compiler output:
a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
a.cc:97:26: error: no matching function for call to 'Graph::hasNegativeCycle()'
   97 |   if (!g.hasNegativeCycle()) {
      |        ~~~~~~~~~~~~~~~~~~^~
a.cc:89:6: note: candidate: 'bool Graph::hasNegativeCycle(ll)'
   89 | bool Graph::hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; }
      |      ^~~~~
a.cc:89:6: note:   candidate expects 1 argument, 0 provided