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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define INF 2000000000
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int, int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define repi(start, end) for (int i = start; i < end; i++)
#define repj(start, end) for (int j = start; j < end; j++)
#define repk(start, end) for (int k = start; k < end; k++)
#define repl(start, end) for (int l = start; l < end; l++)
#define RE return 0;

struct edge {
  int to, cap, rev;
};

int n, k;
bool can[1000][1000];
int used[2000000];

vector<edge> G[2000000];

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
  // cout<<"  v = "<<v<<en
  if (v == t)
    return f;
  used[v] = true;
  repi(0, G[v].size()) {
    edge &e = G[v][i];
    if (!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 max_flow(int s, int t) {
  int i = 0;
  int flow = 0;
  for (;;) {
    memset(used, 0, sizeof(used));
    // cout<<"         "<<i++<<en
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

void solve() {
  int s = n + k, t = s + 1;

  repi(0, n) { add_edge(s, i, 1); }
  repi(0, k) { add_edge(n + i, t, 1); }

  repi(0, n) {
    repj(0, k) {
      if (can[i][j]) {
        add_edge(i, n + j, 1);
      }
    }
  }

  cout << max_flow(s, t) << en
}

int main() {

  repi(0, 1000) {
    repj(0, 1000) { can[i][j] = false; }
  }

  int e, a, b;
  cin >> n >> k >> e;
  repi(0, e) {
    cin >> a >> b;
    can[a][b] = true;
  }

  solve();
  RE
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define INF 2000000000
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int, int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define repi(start, end) for (int i = start; i < end; i++)
#define repj(start, end) for (int j = start; j < end; j++)
#define repk(start, end) for (int k = start; k < end; k++)
#define repl(start, end) for (int l = start; l < end; l++)
#define RE return 0;

struct edge {
  int to, cap, rev;
};

int n, k;
bool can[201][201];
int used[100];

vector<edge> G[100];

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  repi(0, G[v].size()) {
    edge &e = G[v][i];
    if (!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 max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

void solve() {
  int s = n + k, t = s + 1;

  repi(0, n) { add_edge(s, i, 1); }
  repi(0, k) { add_edge(n + i, t, 1); }

  repi(0, n) {
    repj(0, k) {
      if (can[i][j]) {
        add_edge(i, n + j, 1);
      }
    }
  }

  cout << max_flow(s, t) << en
}

int main() {
  /*
  cin>>n>>k;
  repi(0, n){
    int num;
    cout<<"        "<<i<<":"<<en
    cout<<"how many?     ";
    cin>>num;
    cout<<"encode ->   ";
    int a;
    repj(0, num) {cin>>a; can[i][a]=true;}
  }
  cout<<en*/

  int e, a, b;
  cin >> n >> k >> e;
  repi(0, e) {
    cin >> a >> b;
    can[a][b] = true;
  }

  solve();
}