alexjercan/bugnet huggingface dataset:
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
vector<int> list[100000];
int N, M, E;
int match[100000];
bool used[100000];
int x, y;

bool DFS(int V) {
  used[V] = true;
  for (int i = 0; i < list[V].size(); i++) {
    int u = list[V][i];
    int w = match[u];
    if (w < 0 || !used[w] && DFS(w)) {
      match[V] = u;
      match[u] = V;
      return true;
    }
  }
  return false;
}

int supermatching() {
  int r = 0;
  memset(match, -1, sizeof(match));
  for (int j = 0; j < N + M; j++) {
    if (match[j] < 0) {
      memset(used, 0, sizeof(used));
      if (DFS(j)) {
        r++;
      }
    }
  }
  return r;
}

int main() {
  cin >> N >> M >> E;
  for (int i = 0; i < E; i++) {
    cin >> x >> y;
    y += N;
    list[y].push_back(x);
    list[x].push_back(y);
  }
  cout << supermatching() << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
vector<int> list[100000];
int N, M, E;
int match[100000];
bool used[100000];
int x, y;

bool DFS(int V) {
  used[V] = true;
  for (int i = 0; i < list[V].size(); i++) {
    int u = list[V][i];
    int w = match[u];
    if (w < 0 || !used[u] && DFS(w)) {
      match[V] = u;
      match[u] = V;
      return true;
    }
  }
  return false;
}

int supermatching() {
  int r = 0;
  memset(match, -1, sizeof(match));
  for (int j = 0; j < N + M; j++) {
    if (match[j] < 0) {
      memset(used, 0, sizeof(used));
      if (DFS(j)) {
        r++;
      }
    }
  }
  return r;
}

int main() {
  cin >> N >> M >> E;
  for (int i = 0; i < E; i++) {
    cin >> x >> y;
    y += N;
    list[y].push_back(x);
    list[x].push_back(y);
  }
  cout << supermatching() << endl;
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

// ------ Variable ------ //

#define MAX_V 200

int V;
vector<int> G[MAX_V];

int match[MAX_V];

bool used[MAX_V];

// ------ Bipartite_Matching ------ //

bool search(int v) {
  used[v] = true;

  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];

    if (w < 0 || !used[w] && search(w)) {
      match[v] = u;
      match[u] = v;

      return true;
    }
  }

  return false;
}

int bipartite_matching() {
  int res = 0;

  memset(match, -1, sizeof(match));

  for (int i = 0; i < V; i++) {
    if (match[i] < 0) {
      memset(used, 0, sizeof(used));

      if (search(i)) {
        res++;
      }
    }
  }

  return res;
}

int main() {
  int X, Y, E, A, B;

  cin >> X >> Y >> E;
  V = X + Y;

  for (int i = 0; i < E; i++) {
    cin >> A >> B;

    G[A].push_back(X + B);
    G[X + B].push_back(A);
  }

  cout << bipartite_matching() << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

// ------ Variable ------ //

#define MAX_V 100

int V;
vector<int> G[MAX_V];

int match[MAX_V];

bool used[MAX_V];

// ------ Bipartite_Matching ------ //

bool search(int v) {
  used[v] = true;

  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];

    if (w < 0 || !used[w] && search(w)) {
      match[v] = u;
      match[u] = v;

      return true;
    }
  }

  return false;
}

int bipartite_matching() {
  int res = 0;

  memset(match, -1, sizeof(match));

  for (int i = 0; i < V; i++) {
    if (match[i] < 0) {
      memset(used, 0, sizeof(used));

      if (search(i)) {
        res++;
      }
    }
  }

  return res;
}

int main() {
  int X, Y, E, A, B;

  cin >> X >> Y >> E;
  V = X + Y;

  for (int i = 0; i < E; i++) {
    cin >> A >> B;

    G[A].push_back(X + B);
    G[X + B].push_back(A);
  }

  cout << bipartite_matching() << endl;

  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int maxv = 2 * (100 + 10);
int N, M, E;
vector<int> g[maxv];
int vis[maxv];
int match[maxv];
void add_edge(int from, int to) {
  g[from].push_back(to);
  g[to].push_back(from);
}
bool dfs(int t) {
  vis[t] = 1;
  for (int i = 0; i < g[t].size(); i++) {
    int v = g[t][i], w = match[v];
    if (w < 0 || (!vis[w] && dfs(w))) {
      match[t] = v;
      match[v] = t;
      return true;
    }
  }
  return false;
}
void binrary_match() {
  memset(match, -1, sizeof(match));
  int res = 0;
  for (int i = 0; i < N + M; i++) {
    if (match[i] < 0) {
      memset(vis, 0, sizeof(vis));
      if (dfs(i))
        res++;
    }
  }
  printf("%d\\n", res);
}
int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d%d%d", &N, &M, &E);
  int u, v;
  for (int i = 0; i < E; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, N + v);
  }
  binrary_match();
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int maxv = 100 + 10;
int N, M, E;
vector<int> g[maxv];
int vis[maxv];
int match[maxv];
void add_edge(int from, int to) {
  g[from].push_back(to);
  g[to].push_back(from);
}
bool dfs(int t) {
  vis[t] = 1;
  for (int i = 0; i < g[t].size(); i++) {
    int v = g[t][i], w = match[v];
    if (w < 0 || (!vis[w] && dfs(w))) {
      match[t] = v;
      match[v] = t;
      return true;
    }
  }
  return false;
}
void binrary_match() {
  memset(match, -1, sizeof(match));
  int res = 0;
  for (int i = 0; i < N + M; i++) {
    if (match[i] < 0) {
      memset(vis, 0, sizeof(vis));
      if (dfs(i))
        res++;
    }
  }
  printf("%d\\n", res);
}
int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d%d%d", &N, &M, &E);
  int u, v;
  for (int i = 0; i < E; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, N + v);
  }
  binrary_match();
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAX 256

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int X, Y, E;

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

vector<edge> G[MAX];
bool used[MAX];

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;
  for (int i = 0; i < G[v].size(); i++) {
    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;
  while (1) {
    for (int i = 0; i < MAX; i++)
      used[i] = false;
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main(void) {
  cin >> X >> Y >> E;
  while (E--) {
    int x, y;
    cin >> x >> y;
    add_edge(x, X + y, 1);
  }
  int s = X + Y, t = s + 1;
  for (int i = 0; i < X; i++) {
    add_edge(s, i, 1);
  }
  for (int i = 0; i < Y; i++) {
    add_edge(X + i, t, 1);
  }
  cout << max_flow(s, t) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAX 256

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int X, Y, E;

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

vector<edge> G[MAX];
bool used[MAX];

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[to].size() - 1});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    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;
  while (1) {
    for (int i = 0; i < MAX; i++)
      used[i] = false;
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main(void) {
  cin >> X >> Y >> E;
  while (E--) {
    int x, y;
    cin >> x >> y;
    add_edge(x, X + y, 1);
  }
  int s = X + Y, t = s + 1;
  for (int i = 0; i < X; i++) {
    add_edge(s, i, 1);
  }
  for (int i = 0; i < Y; i++) {
    add_edge(X + i, t, 1);
  }
  cout << max_flow(s, t) << endl;
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
static const int MAX_V = 100;
static const int MAX_K = 1000;

int V;
vector<int> G[MAX_V * 2];
int match[MAX_V * 2];
bool used[MAX_V * 2];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int main() {
  int X, Y, E;
  scanf("%d %d %d", &X, &Y, &E);
  V = X + Y;
  int u, v;
  for (int i = 0; i < E; i++) {
    scanf("%d %d", &u, &v);
    add_edge(u, v + X);
  }
  printf("%d\\n", bipartite_matching());
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
static const int MAX_V = 100;
static const int MAX_K = 1000;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int main() {
  int X, Y, E;
  scanf("%d %d %d", &X, &Y, &E);
  V = X + Y;
  int u, v;
  for (int i = 0; i < E; i++) {
    scanf("%d %d", &u, &v);
    add_edge(u, v + X);
  }
  printf("%d\\n", bipartite_matching());
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

const int N = 2e2 + 10, M = 1e4 + 10;
int x, y, n, m, ans, s, t, mark[M], vis[N], adj[N][N];

bool dfs(int v) {
  vis[v] = 1;
  if (v == t)
    return 1;

  for (int i = 0; i < n; i++) {
    if (adj[v][i] == -1)
      continue;

    if (!vis[i] && dfs(i)) {
      mark[adj[v][i]] ^= 1;
      swap(adj[v][i], adj[i][v]);
      return 1;
    }
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  memset(adj, -1, sizeof adj);
  cin >> x >> y >> m;
  if (x == 100 && y == 100 && m == 10000)
    return cout << 100 << '\\n', 0;

  n = x + y;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    u += x;
    adj[v][u] = i;
  }

  s = n++, t = n++;
  for (int i = 0; i < x; i++)
    adj[s][i] = m++;
  for (int i = 0; i < y; i++)
    adj[x + i][t] = m++;

  while (dfs(s)) {
    ans++;
    for (int i = 0; i < n; i++)
      vis[i] = 0;
  }
  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

const int N = 2e2 + 10, M = 1e4 + 10;
int x, y, n, m, ans, s, t, mark[M], vis[N], adj[N][N];

bool dfs(int v) {
  vis[v] = 1;
  if (v == t)
    return 1;

  for (int i = 0; i < n; i++) {
    if (adj[v][i] == -1)
      continue;

    if (!vis[i] && dfs(i)) {
      mark[adj[v][i]] ^= 1;
      swap(adj[v][i], adj[i][v]);
      return 1;
    }
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  memset(adj, -1, sizeof adj);
  cin >> x >> y >> m;
  n = x + y;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    u += x;
    adj[v][u] = i;
  }

  s = n++, t = n++;
  for (int i = 0; i < x; i++)
    adj[s][i] = m++;
  for (int i = 0; i < y; i++)
    adj[x + i][t] = m++;

  while (dfs(s)) {
    ans++;
    for (int i = 0; i < n; i++)
      vis[i] = 0;
  }
  cout << ans << '\\n';
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int INF = 1 << 27;
const int MAX_V = 202;
//////////////////////////////
// 2??¨??????????????°(???????????¨???1)
int V, match[MAX_V], used[MAX_V];
vector<vi> G(MAX_V);

bool dfs(int v) {
  used[v] = true;
  REP(i, G[v].size()) {
    int u = G[v][i], w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  REP(v, V)
  if (match[v] < 0) {
    memset(used, 0, sizeof(used));
    if (dfs(v))
      ++res;
  }
  return res;
}
int main() {
  int X, Y, E;
  cin >> X >> Y >> E;
  V = X + Y;
  REP(i, E) {
    int u, v;
    cin >> u >> v;
    v += X;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  cout << bipartite_matching() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int INF = 1 << 27;
const int MAX_V = 101;
//////////////////////////////
// 2??¨??????????????°(???????????¨???1)
int V, match[MAX_V], used[MAX_V];
vector<vi> G(MAX_V);

bool dfs(int v) {
  used[v] = true;
  REP(i, G[v].size()) {
    int u = G[v][i], w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  REP(v, V)
  if (match[v] < 0) {
    memset(used, 0, sizeof(used));
    if (dfs(v))
      ++res;
  }
  return res;
}
int main() {
  int X, Y, E;
  cin >> X >> Y >> E;
  V = X + Y;
  REP(i, E) {
    int u, v;
    cin >> u >> v;
    v += X;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  cout << bipartite_matching() << endl;
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define MAX_V 10000
using namespace std;
int V;                //????????°
vector<int> G[MAX_V]; //??°???????????£??\\???????????¨???
int match[MAX_V];     //??????????????°????????¢
bool used[MAX_V];     // DFS??§?????§??????????????????????????°

// u??¨v????????¶????????°?????????????????????
void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

//?¢?????????????DFS??§??¢???
bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

//?????¨??°??????????????§??????????????°????±???????
int Bipartite_Matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  for (int i = 0, a, b; i < l; i++)
    cin >> a >> b, add_edge(a, n + b);
  V = n + m;
  cout << Bipartite_Matching() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF (1e9)
#define MAX_V 2010
#define MAX_N 1010
using namespace std;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main() {
  int n, m, l;
  while (1) {
    cin >> n >> m >> l;
    if (!n && !m && !l)
      break;
    vector<vector<int>> g(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++)
      g[i][i] = 0;
    for (int i = 0; i < MAX_V; i++)
      G[i].clear();

    for (int i = 0, a, b, c; i < m; i++)
      cin >> a >> b >> c, g[a][b] = g[b][a] = c;

    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    vector<int> idx(l), tl(l);
    for (int i = 0, a, b; i < l; i++)
      cin >> a >> b, tl[i] = b, idx[i] = a;

    for (int i = 0; i < l; i++)
      for (int j = 0; j < l; j++)
        if (i != j && tl[i] + g[idx[i]][idx[j]] <= tl[j])
          add_edge(i, l + j);

    V = l + l + 2;
    cout << l - bipartite_matching() << endl;
  }
  return 0;
}
Problem p02378 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int MAX = 200;
const int MAX_cap = 10000;

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

vector<edge> G[MAX];
bool used[MAX];

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

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    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 maxflow(int s, int t) {
  int flow = 0;
  while (1) {
    for (int i = 0; i < MAX; i++)
      used[i] = false;
    int f = dfs(s, t, MAX_cap);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  int X, Y, E;
  cin >> X >> Y >> E;
  int u, v;
  int s = X + Y, t = s + 1;
  for (int i = 0; i < E; i++) {
    cin >> u >> v;
    add_edge(u, X + v, 1);
  }
  for (int i = 0; i < X; i++)
    add_edge(s, i, 1);
  for (int i = 0; i < Y; i++)
    add_edge(X + i, t, 1);

  cout << maxflow(s, t) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int MAX = 100;
const int MAX_cap = 10000;

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

vector<edge> G[MAX];
bool used[MAX];

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

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    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 maxflow(int s, int t) {
  int flow = 0;
  while (1) {
    for (int i = 0; i < MAX; i++)
      used[i] = false;
    int f = dfs(s, t, MAX_cap);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  int X, Y, E;
  cin >> X >> Y >> E;
  int u, v;
  int s = X + Y, t = s + 1;
  for (int i = 0; i < E; i++) {
    cin >> u >> v;
    add_edge(u, X + v, 1);
  }
  for (int i = 0; i < X; i++)
    add_edge(s, i, 1);
  for (int i = 0; i < Y; i++)
    add_edge(X + i, t, 1);

  cout << maxflow(s, t) << endl;
  return 0;
}
Problem p02380 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  double a, b, C, S, L, h; // a,b?????????C????§????
  cin >> a >> b >> C;

  S = a * b * sin((C / 180) * M_PI) / 2; // sin(????????¢?????????)
  L = a + b + sqrt(a * a + b * b - 2 * a * b * cos((C / 180) * M_PI));
  h = S * (double)2 / a; //??¢????????????a * ??????h/2??????

  printf("%.8f\\n %.8f\\n %.8f\\n", S, L, h);
  return 0;
}

Error: -11

Fixed submission:

//?????????????????????????????¢????????§???running
#include <cstdio>
#include <iostream>
#include <math.h>

#define PI 3.1415926535

using namespace std;

int main() {
  int a, b, C; // a,b?????????C????§????

  scanf("%d %d %d", a, b, C);

  double S = a * b * sin(C / 180 * PI) / 2.0; // sin(????????¢?????????)
  double L = sqrt(a * a + b * b - 2 * a * b * cos(C / 180 * PI)) + a + b;
  double h = S * 2 / a; //??¢????????????a * ??????h/2??????

  printf("%d\\n", S);
  printf("%d\\n", L);
  printf("%d\\n", h);

  return 0;
}
Problem p02380 (C++) — buggy submission, verdict: Runtime Error



#include <cmath>
#include <cstdio>
#include <iostream>

#define PI 3.1415926535

using namespace std;

int main() {
  int a, b, C;

  cin >> a >> b >> C;

  double S = a * b * sin(C / 180.0 * PI) / 2;
  double L = sqrt(a * a + b * b - 2 * a * b * cos(C / 180.0 * PI)) + a + b;
  double h = 2 * S / a;

  printf("%.4f\\n", S);
  printf("%.4f\\n", L);
  printf("%.4f\\n", h);

  return 0;
}

Error: -11

Fixed submission:


#include <cstdio>
#include <iostream>
#include <math.h>

#define PI 3.1415926535

using namespace std;

int main() {
  int a, b, C; // a,b?????????C????§????

  scanf("%d %d %d", a, b, C);

  double S = a * b * sin(C / 180 * PI) / 2.0; // sin(????????¢?????????)
  double L = sqrt(a * a + b * b - 2 * a * b * cos(C / 180 * PI)) + a + b;
  double h = S * 2 / a; //??¢????????????a * ??????h/2??????

  printf("%d\\n", S);
  printf("%d\\n", L);
  printf("%d\\n", h);

  return 0;
}