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 * 1e18;
const ll MOD = 1e9 + 7;

ll goal;

// O(|V||E|)
class Graph {
private:
  ll V; // 1index. 1-Vまで
  vector<pair<ll, pll>> edges;
  bool _hasNegativeCycle = false;
  vector<ll> dist(this->V, INF);

public:
  Graph(ll V);
  void addEdge(ll u, ll v, ll w);
  void bellmanFord(ll src);
  ll getDistance(ll n);
  bool hasNegativeCycle();
};
Graph::Graph(ll V) { this->V = V; }
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 = 1; i <= this->V; 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->_hasNegativeCycle = true;
    }
  }
}
ll Graph::getDistance(ll n) { return this->dist[n]; }
bool Graph::hasNegativeCycle() { return this->_hasNegativeCycle; }

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], b[m], -c[m]); }
  g.bellmanFord(1);

  if (!g.hasNegativeCycle()) {
    print(-g.getDistance[N]);
  } 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:48:23: error: expected identifier before '->' token
   48 |   vector<ll> dist(this->V, INF);
      |                       ^~
a.cc:48:23: error: expected ',' or '...' before '->' token
a.cc:48:19: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions]
   48 |   vector<ll> dist(this->V, INF);
      |                   ^~~~~~
a.cc: In member function 'void Graph::bellmanFord(ll)':
a.cc:60:13: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   60 |   this->dist[src] = 0;
      |             ^
a.cc:68:21: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   68 |       if (this->dist[u] + w < this->dist[v]) {
      |                     ^
a.cc:68:41: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   68 |       if (this->dist[u] + w < this->dist[v]) {
      |                                         ^
a.cc:69:19: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   69 |         this->dist[v] = this->dist[u] + w;
      |                   ^
a.cc:69:35: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   69 |         this->dist[v] = this->dist[u] + w;
      |                                   ^
a.cc:78:19: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   78 |     if (this->dist[u] + w < this->dist[v]) {
      |                   ^
a.cc:78:39: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   78 |     if (this->dist[u] + w < this->dist[v]) {
      |                                       ^
a.cc: In member function 'll Graph::getDistance(ll)':
a.cc:83:48: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   83 | ll Graph::getDistance(ll n) { return this->dist[n]; }
      |                                                ^
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:93:25: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   93 |     print(-g.getDistance[N]);
      |                         ^
a.cc:28:26: note: in definition of macro 'print'
   28 | #define print(x) cout << x << endl
      |                          ^