Language: C++

// =================グラフテンプレート==================

// costの部分の型は指定できます
template <typename T>
struct edge {
  int from, to;
  T cost;

  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

  // 行き先を代入できる
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  // intにキャスト(?)するとかなんとか
  operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;

template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
using Matrix = vector<vector<T>>;

using UnWeightedGraph = vector<vector<int>>;

// =============ベルマン・フォード法=============
// 負の閉路を検出できます(空のvectorを返します)
// bellman<距離の型>(重み付き辺の集合,頂点数,始点)

template <typename T>
vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(V, INF);

  dist[s] = 0;
  for (int i = 0; i < V - 1; i++) {
    for (auto &e : edges) {
      if (dist[e.from] != INF)  // 遷移できるなら
        dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
    }
  }
  for (auto &e : edges) {  // 離島、負の閉路について
    if (dist[e.from] == INF) continue;
    if (dist[e.from] + e.cost < dist[e.to]) return vector<T>();
  }
  return dist;
}

// ====================================================================

int main() {
  int n, m, r;
  cin >> n >> m;
  r=0;
  Edges<ll> edges;
  for (int i = 0; i < m; i++) {
    int s, t;
    ll c;
    cin >> s >> t >> c;
    s--;t--;
    edges.push_back(edge<ll>{s, t, -c});
  }

  vector<ll> ans = bellman_ford(edges, n, r);

  if (ans.size())
    cout<<-ans[ans.size()-1]<<endl;
  else
    cout << "inf" << endl;
}

Compiler output:
a.cc:23:15: error: 'vector' does not name a type
   23 | using Edges = vector<edge<T>>;
      |               ^~~~~~
a.cc:26:23: error: 'vector' does not name a type
   26 | using WeightedGraph = vector<Edges<T>>;
      |                       ^~~~~~
a.cc:29:16: error: 'vector' does not name a type
   29 | using Matrix = vector<vector<T>>;
      |                ^~~~~~
a.cc:31:25: error: 'vector' does not name a type
   31 | using UnWeightedGraph = vector<vector<int>>;
      |                         ^~~~~~
a.cc:38:1: error: 'vector' does not name a type
   38 | vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:60:3: error: 'cin' was not declared in this scope
   60 |   cin >> n >> m;
      |   ^~~
a.cc:62:3: error: 'Edges' was not declared in this scope
   62 |   Edges<ll> edges;
      |   ^~~~~
a.cc:62:9: error: 'll' was not declared in this scope
   62 |   Edges<ll> edges;
      |         ^~
a.cc:62:13: error: 'edges' was not declared in this scope; did you mean 'edge'?
   62 |   Edges<ll> edges;
      |             ^~~~~
      |             edge
a.cc:65:7: error: expected ';' before 'c'
   65 |     ll c;
      |       ^~
      |       ;
a.cc:66:22: error: 'c' was not declared in this scope
   66 |     cin >> s >> t >> c;
      |                      ^
a.cc:71:3: error: 'vector' was not declared in this scope
   71 |   vector<ll> ans = bellman_ford(edges, n, r);
      |   ^~~~~~
a.cc:71:14: error: 'ans' was not declared in this scope
   71 |   vector<ll> ans = bellman_ford(edges, n, r);
      |              ^~~
a.cc:71:20: error: 'bellman_ford' was not declared in this scope
   71 |   vector<ll> ans = bellman_ford(edges, n, r);
      |                    ^~~~~~~~~~~~
a.cc:74:5: error: 'cout' was not declared in this scope
   74 |     cout<<-ans[ans.size()-1]<<endl;
      |     ^~~~
a.cc:74:31: error: 'endl' was not declared in this scope
   74 |     cout<<-ans[ans.size()-1]<<endl;
      |                               ^~~~
a.cc:76:5: error: 'cout' was not declared in this scope
   76 |     cout << "inf" << endl;
      |     ^~~~
a.cc:76:22: error: 'endl' was not declared in this scope
   76 |     cout << "inf" << endl;
      |                      ^~~~