Language: C++

class MinimumCostFlow {
  struct Edge {
    int to;
    long long cost, capacity;
    int rev_id;
    Edge(int to, long long cost, long long cap, int id)
        : to(to), cost(cost), capacity(cap), rev_id(id){};
    Edge() { Edge(0, 0, 0, 0); }
  };
  struct Prev {
    LL cost;
    int from, id;
  };
  using Graph = vector<vector<Edge>>;
  using Flow = vector<vector<long long>>;
  int n;
  Graph graph;
  Flow flow;
  vector<Prev> prev;
  vector<long long> potential;

 public:
  MinimumCostFlow(int n) : n(n), graph(n), prev(n, {LINF, -1, -1}), potential(n) {}

  long long minimumCostFlow(int s, int t, LL f) {
    LL ret = 0;
    //int size = graph.size();
    //vector<LL> h(size);
    //vector<Prev> prev(size, {LINF, -1, -1});  //mincost, from,id
    for (bellman_ford(s); f > 0; dijkstra(s)) {
      if (prev[t].cost == LINF) return -1;
      for (int i = 0; i < n; ++i) potential[i] = min(potential[i] + prev[i].cost, LINF);
      LL d = f;
      for (int v = t; v != s; v = prev[v].from) {
        //DBG(v)
        //DBG(prev[v].from)
        d = min(d, graph[prev[v].from][prev[v].id].capacity - flow[prev[v].from][v]);
        //DBG(d)
      }
      f -= d;
      ret += d * potential[t];
      //DBG(ret)
      for (int v = t; v != s; v = prev[v].from) {
        flow[prev[v].from][v] += d;
        flow[v][prev[v].from] -= d;
      }
    }
    return ret;
  }

 private:
  bool dijkstra(const int start) {
    int visited = 0, N = graph.size();
    fill(prev.begin(), prev.end(), (Prev){LINF, -1, -1});
    typedef tuple<LL, int, int, int> TP;
    priority_queue<TP, vector<TP>, greater<TP>> pque;
    pque.emplace(0, start, 0, -1);
    LL cost;
    int place, from, id;
    while (!pque.empty()) {
      tie(cost, place, from, id) = pque.top();
      pque.pop();
      if (prev[place].from != -1) continue;
      prev[place] = {cost, from, id};
      visited++;
      if (visited == N) return true;
      for (int i = 0; i < (int)graph[place].size(); ++i) {
        auto e = &graph[place][i];
        if (e->capacity > flow[place][e->to] && prev[e->to].from == -1) {
          pque.emplace(e->cost + cost - potential[e->to] + potential[place], e->to, place, i);
        }
      }
    }
    return false;
  }
  bool bellman_ford(const int start) {
    int s = graph.size();
    bool update = false;
    prev[start] = (Prev){0ll, start, -1};
    for (int i = 0; i < s; ++i, update = false) {
      for (int j = 0; j < s; ++j) {
        for (auto &e : graph[j]) {
          if (e.capacity == 0) continue;
          if (prev[j].cost != LINF && prev[e.to].cost > prev[j].cost + e.cost) {
            prev[e.to].cost = prev[j].cost + e.cost;
            prev[e.to].from = j;
            prev[e.to].id = e.rev_id;
            update = true;
            if (i == s - 1) return false;
          }
        }
      }
      if (!update) break;
    }
    return true;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  LL flow;
  cin >> n >> m >> flow;
  MinimumCostFlow mcf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    LL cost, cap;
    cin >> a >> b >> cap >> cost;
    mcf.addEdge(a, b, cap, cost);
  }
  cout << mcf.minimumCostFlow(0, n - 1, flow) << endl;
  return 0;
}


Compiler output:
a.cc:11:5: error: 'LL' does not name a type
   11 |     LL cost;
      |     ^~
a.cc:14:17: error: 'vector' does not name a type
   14 |   using Graph = vector<vector<Edge>>;
      |                 ^~~~~~
a.cc:15:16: error: 'vector' does not name a type
   15 |   using Flow = vector<vector<long long>>;
      |                ^~~~~~
a.cc:17:3: error: 'Graph' does not name a type
   17 |   Graph graph;
      |   ^~~~~
a.cc:18:3: error: 'Flow' does not name a type
   18 |   Flow flow;
      |   ^~~~
a.cc:19:3: error: 'vector' does not name a type
   19 |   vector<Prev> prev;
      |   ^~~~~~
a.cc:20:3: error: 'vector' does not name a type
   20 |   vector<long long> potential;
      |   ^~~~~~
a.cc:25:43: error: 'LL' has not been declared
   25 |   long long minimumCostFlow(int s, int t, LL f) {
      |                                           ^~
a.cc: In constructor 'MinimumCostFlow::MinimumCostFlow(int)':
a.cc:23:34: error: class 'MinimumCostFlow' does not have any field named 'graph'
   23 |   MinimumCostFlow(int n) : n(n), graph(n), prev(n, {LINF, -1, -1}), potential(n) {}
      |                                  ^~~~~
a.cc:23:44: error: class 'MinimumCostFlow' does not have any field named 'prev'
   23 |   MinimumCostFlow(int n) : n(n), graph(n), prev(n, {LINF, -1, -1}), potential(n) {}
      |                                            ^~~~
a.cc:23:53: error: 'LINF' was not declared in this scope
   23 |   MinimumCostFlow(int n) : n(n), graph(n), prev(n, {LINF, -1, -1}), potential(n) {}
      |                                                     ^~~~
a.cc:23:69: error: class 'MinimumCostFlow' does not have any field named 'potential'
   23 |   MinimumCostFlow(int n) : n(n), graph(n), prev(n, {LINF, -1, -1}), potential(n) {}
      |                                                                     ^~~~~~~~~
a.cc: In member function 'long long int MinimumCostFlow::minimumCostFlow(int, int, int)':
a.cc:26:5: error: 'LL' was not declared in this scope
   26 |     LL ret = 0;
      |     ^~
a.cc:31:11: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   31 |       if (prev[t].cost == LINF) return -1;
      |           ^~~~
      |           Prev
a.cc:31:27: error: 'LINF' was not declared in this scope
   31 |       if (prev[t].cost == LINF) return -1;
      |                           ^~~~
a.cc:32:35: error: 'potential' was not declared in this scope
   32 |       for (int i = 0; i < n; ++i) potential[i] = min(potential[i] + prev[i].cost, LINF);
      |                                   ^~~~~~~~~
a.cc:32:69: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   32 |       for (int i = 0; i < n; ++i) potential[i] = min(potential[i] + prev[i].cost, LINF);
      |                                                                     ^~~~
      |                                                                     Prev
a.cc:32:83: error: 'LINF' was not declared in this scope
   32 |       for (int i = 0; i < n; ++i) potential[i] = min(potential[i] + prev[i].cost, LINF);
      |                                                                                   ^~~~
a.cc:32:50: error: 'min' was not declared in this scope
   32 |       for (int i = 0; i < n; ++i) potential[i] = min(potential[i] + prev[i].cost, LINF);
      |                                                  ^~~
a.cc:33:10: error: expected ';' before 'd'
   33 |       LL d = f;
      |          ^
a.cc:34:35: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   34 |       for (int v = t; v != s; v = prev[v].from) {
      |                                   ^~~~
      |                                   Prev
a.cc:37:9: error: 'd' was not declared in this scope
   37 |         d = min(d, graph[prev[v].from][prev[v].id].capacity - flow[prev[v].from][v]);
      |         ^
a.cc:37:20: error: 'graph' was not declared in this scope
   37 |         d = min(d, graph[prev[v].from][prev[v].id].capacity - flow[prev[v].from][v]);
      |                    ^~~~~
a.cc:37:63: error: 'flow' was not declared in this scope
   37 |         d = min(d, graph[prev[v].from][prev[v].id].capacity - flow[prev[v].from][v]);
      |                                                               ^~~~
a.cc:37:13: error: 'min' was not declared in this scope
   37 |         d = min(d, graph[prev[v].from][prev[v].id].capacity - flow[prev[v].from][v]);
      |             ^~~
a.cc:40:12: error: 'd' was not declared in this scope
   40 |       f -= d;
      |            ^
a.cc:41:7: error: 'ret' was not declared in this scope
   41 |       ret += d * potential[t];
      |       ^~~
a.cc:41:18: error: 'potential' was not declared in this scope
   41 |       ret += d * potential[t];
      |                  ^~~~~~~~~
a.cc:43:35: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   43 |       for (int v = t; v != s; v = prev[v].from) {
      |                                   ^~~~
      |                                   Prev
a.cc:44:9: error: 'flow' was not declared in this scope
   44 |         flow[prev[v].from][v] += d;
      |         ^~~~
a.cc:48:12: error: 'ret' was not declared in this scope
   48 |     return ret;
      |            ^~~
a.cc: In member function 'bool MinimumCostFlow::dijkstra(int)':
a.cc:53:26: error: 'graph' was not declared in this scope
   53 |     int visited = 0, N = graph.size();
      |                          ^~~~~
a.cc:54:10: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   54 |     fill(prev.begin(), prev.end(), (Prev){LINF, -1, -1});
      |          ^~~~
      |          Prev
a.cc:54:43: error: 'LINF' was not declared in this scope
   54 |     fill(prev.begin(), prev.end(), (Prev){LINF, -1, -1});
      |                                           ^~~~
a.cc:54:5: error: 'fill' was not declared in this scope
   54 |     fill(prev.begin(), prev.end(), (Prev){LINF, -1, -1});
      |     ^~~~
a.cc:55:13: error: 'tuple' does not name a type
   55 |     typedef tuple<LL, int, int, int> TP;
      |             ^~~~~
a.cc:56:5: error: 'priority_queue' was not declared in this scope
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |     ^~~~~~~~~~~~~~
a.cc:56:20: error: 'TP' was not declared in this scope
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |                    ^~
a.cc:56:24: error: 'vector' was not declared in this scope
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |                        ^~~~~~
a.cc:56:34: error: expected primary-expression before ',' token
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |                                  ^
a.cc:56:36: error: 'greater' was not declared in this scope
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |                                    ^~~~~~~
a.cc:56:49: error: 'pque' was not declared in this scope
   56 |     priority_queue<TP, vector<TP>, greater<TP>> pque;
      |                                                 ^~~~
a.cc:58:5: error: 'LL' was not declared in this scope
   58 |     LL cost;
      |     ^~
a.cc:61:11: error: 'cost' was not declared in this scope; did you mean 'const'?
   61 |       tie(cost, place, from, id) = pque.top();
      |           ^~~~
      |           const
a.cc:61:7: error: 'tie' was not declared in this scope
   61 |       tie(cost, place, from, id) = pque.top();
      |       ^~~
a.cc:69:27: error: 'flow' was not declared in this scope
   69 |         if (e->capacity > flow[place][e->to] && prev[e->to].from == -1) {
      |                           ^~~~
a.cc:70:41: error: 'potential' was not declared in this scope
   70 |           pque.emplace(e->cost + cost - potential[e->to] + potential[place], e->to, place, i);
      |                                         ^~~~~~~~~
a.cc: In member function 'bool MinimumCostFlow::bellman_ford(int)':
a.cc:77:13: error: 'graph' was not declared in this scope
   77 |     int s = graph.size();
      |             ^~~~~
a.cc:79:5: error: 'prev' was not declared in this scope; did you mean 'Prev'?
   79 |     prev[start] = (Prev){0ll, start, -1};
      |     ^~~~
      |     Prev
a.cc:79:40: error: too many initializers for 'MinimumCostFlow::Prev'
   79 |     prev[start] = (Prev){0ll, start, -1};
      |                                        ^
a.cc:84:31: error: 'LINF' was not declared in this scope
   84 |           if (prev[j].cost != LINF && prev[e.to].cost > prev[j].cost + e.cost) {
      |                               ^~~~
a.cc: In function 'int main()':
a.cc:100:3: error: 'cin' was not declared in this scope
  100 |   cin.tie(0);
      |   ^~~
a.cc:101:3: error: 'ios' has not been declared
  101 |   ios::sync_with_stdio(false);
      |   ^~~
a.cc:103:3: error: 'LL' was not declared in this scope
  103 |   LL flow;
      |   ^~
a.cc:104:20: error: 'flow' was not declared in this scope
  104 |   cin >> n >> m >> flow;
      |                    ^~~~
a.cc:108:7: error: expected ';' before 'cost'
  108 |     LL cost, cap;
      |       ^~~~~
      |       ;
a.cc:109:22: error: 'cap' was not declared in this scope
  109 |     cin >> a >> b >> cap >> cost;
      |                      ^~~
a.cc:109:29: error: 'cost' was not declared in this scope; did you mean 'const'?
  109 |     cin >> a >> b >> cap >> cost;
      |                             ^~~~
      |                             const
a.cc:110:9: error: 'class MinimumCostFlow' has no member named 'addEdge'; did you mean 'struct MinimumCostFlow::Edge'? (not accessible from this context)
  110 |     mcf.addEdge(a, b, cap, cost);
      |         ^~~~~~~
a.cc:2:10: note: declared private here
    2 |   struct Edge {
      |          ^~~~
a.cc:112:3: error: 'cout' was not declared in this scope
  112 |   cout << mcf.minimumCostFlow(0, n - 1, flow) << endl;
      |   ^~~~
a.cc:112:50: error: 'endl' was not declared in this scope
  112 |   cout << mcf.minimumCostFlow(0, n - 1, flow) << endl;
      |                                                  ^~~~