Problem p02376 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
const int INF = 20000000;
using namespace std;

const int MAX_V = 201;

class Edge {
public:
  int to, cap, rev;
};

typedef vector<vector<Edge>> AdjList;
AdjList G(MAX_V);
bool used[MAX_V];

void addEdge(int from, int to, int cap) {
  G[from].emplace_back(Edge{to, cap, static_cast<int>(G[to].size())});
  G[to].emplace_back(Edge{from, 0, static_cast<int>(G[from].size() - 1)});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  rep(i, G[v].size()) {
    Edge &e = G[v][i];
    if (not used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  while (true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  int v, e;
  cin >> v >> e;
  rep(i, e) {
    int a, b, c;
    cin >> a >> b >> c;
    addEdge(a, b, c);
  }
  cout << maxFlow(0, v - 1) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_V = 105;

class Edge {
public:
  int to, cap, rev;
  Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
};

class Node {
public:
  int dis;
  bool isUsed;
  Node() {
    this->dis = INF;
    this->isUsed = 0;
  }
};

typedef vector<vector<Edge>> AdjList;
AdjList G(MAX_V);
bool used[MAX_V];

void addEdge(int from, int to, int cap) {
  G[from].emplace_back(Edge{to, cap, static_cast<int>(G[to].size())});
  G[to].emplace_back(Edge{from, 0, static_cast<int>(G[from].size())});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  rep(i, G[v].size()) {
    Edge &e = G[v][i];
    if (not used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  while (true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  int v, e;
  cin >> v >> e;
  rep(i, e) {
    int a, b, c;
    cin >> a >> b >> c;
    addEdge(a, b, c);
  }
  cout << maxFlow(0, v - 1) << endl;
}