alexjercan/bugnet huggingface dataset:
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int a, b, c, n;
  while (cin >> a >> b >> c, a + b + c) {
    cin >> n;
    vector<int> in(a + b + c + 1, 2);
    vector<vector<int>> jud(n, vector<int>(4, 0));
    for (int l = 0; l < n; l++) {
      int i, j, k, r;
      cin >> i >> j >> k >> r;
      if (r == 1) {
        in[i] = in[j] = in[k] = 1;
      }
      jud[l][0] = i;
      jud[l][1] = j;
      jud[l][2] = k;
      jud[l][3] = r;
    }

    for (int i = 0; i < jud.size(); i++) {
      if (jud[i][3] == 0) {
        if (in[jud[i][0]] == 1 && in[jud[i][1]] == 1)
          in[jud[i][2]] = 0;
        if (in[jud[i][2]] == 1 && in[jud[i][0]] == 1)
          in[jud[i][1]] = 0;
        if (in[jud[i][2]] == 1 && in[jud[i][1]] == 1)
          in[jud[i][0]] = 0;
      }
    }

    for (int i = 1; i < in.size(); i++)
      cout << in[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int a, b, c, n;
  while (cin >> a >> b >> c >> n, a + b + c + n) {
    vector<int> in(a + b + c + 1, 2);
    vector<vector<int>> jud(n, vector<int>(4, 0));
    for (int l = 0; l < n; l++) {
      int i, j, k, r;
      cin >> i >> j >> k >> r;
      if (r == 1) {
        in[i] = in[j] = in[k] = 1;
      }
      jud[l][0] = i;
      jud[l][1] = j;
      jud[l][2] = k;
      jud[l][3] = r;
    }

    for (int i = 0; i < jud.size(); i++) {
      if (jud[i][3] == 0) {
        if (in[jud[i][0]] == 1 && in[jud[i][1]] == 1)
          in[jud[i][2]] = 0;
        if (in[jud[i][2]] == 1 && in[jud[i][0]] == 1)
          in[jud[i][1]] = 0;
        if (in[jud[i][2]] == 1 && in[jud[i][1]] == 1)
          in[jud[i][0]] = 0;
      }
    }

    for (int i = 1; i < in.size(); i++)
      cout << in[i] << endl;
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

  int a, b, c;
  while (true) {
    cin >> a >> b >> c;
    if (a + b + c == 0)
      break;
    int n;
    cin >> n;
    vector<int> vec(a + b + c, 2), r(n);
    vector<vector<int>> a(n, vector<int>(3));
    REP(i, n) {
      cin >> a[i][0] >> a[i][1] >> a[i][2] >> r[i];
      if (r[i] == 1) {
        REP(j, 3) vec[a[i][j] - 1] = 1;
      }
    }

    REP(i, n) {
      if (r[i] == 0) {
        int ok = 0;
        REP(j, 3) ok += vec[a[i][j] - 1] == 1 ? 1 : 0;
        if (ok == 2) {
          REP(j, 3) {
            if (vec[a[i][j] - 1] != 1)
              vec[a[i][j] - 1] = 0;
          }
        }
      }
    }
    for (auto x : vec)
      cout << x << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

  int a, b, c;
  while (true) {
    cin >> a >> b >> c;
    if (a + b + c == 0)
      break;
    int n;
    cin >> n;
    vector<int> vec(a + b + c, 2), r(n);
    vector<vector<int>> a(n, vector<int>(3));
    REP(i, n) cin >> a[i][0] >> a[i][1] >> a[i][2] >> r[i];

    REP(k, 1001) REP(i, n) {
      if (r[i] == 1) {
        REP(j, 3) vec[a[i][j] - 1] = 1;
      } else {
        int ok = 0;
        REP(j, 3) ok += vec[a[i][j] - 1] == 1 ? 1 : 0;
        cout << i << " " << ok << endl;
        if (ok == 2) {
          REP(j, 3) {
            if (vec[a[i][j] - 1] != 1)
              vec[a[i][j] - 1] = 0;
          }
        }
      }
    }
    for (auto x : vec)
      cout << x << endl;
  }
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  while (true) {
    int parts[301], d[1000][3], g[1000];
    int a, b, c, N;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;
    cin >> N;
    for (int i = 1; i <= a + b + c; i++) {
      parts[i] = 2;
    }
    for (int i = 0; i < N; i++) {
      cin >> d[i][0] >> d[i][1] >> d[i][2] >> g[i];
      if (g[i] == 1) {
        for (int j = 0; j < 3; j++)
          parts[d[i][j]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (g[i] == 0) {
        for (int j = 0; j < 3; j++) {
          if (parts[d[i][(j + 1) % 3]] == 1 && parts[d[i][(j + 2) % 3]] == 1)
            parts[d[i][j]] = 0;
        }
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << parts[i] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (true) {
    int parts[301], d[301][3], g[1000];
    int a, b, c, N;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;
    cin >> N;
    for (int i = 1; i <= a + b + c; i++) {
      parts[i] = 2;
    }
    for (int i = 0; i < N; i++) {
      cin >> d[i][0] >> d[i][1] >> d[i][2] >> g[i];
      if (g[i] == 1) {
        for (int j = 0; j < 3; j++)
          parts[d[i][j]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (g[i] == 0) {
        for (int j = 0; j < 3; j++) {
          if (parts[d[i][(j + 1) % 3]] == 1 && parts[d[i][(j + 2) % 3]] == 1)
            parts[d[i][j]] = 0;
        }
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << parts[i] << endl;
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int ap[1005], bp[1005], cp[1005], abc[1005], r[1005];
int n, n1, n2, n3;

int main() {

  while (1) {

    cin >> n1 >> n2 >> n3;
    if (n1 == 0 && n2 == 0 && n3 == 0)
      break;
    cin >> n;

    for (int i = 0; i <= n1 + n2 + n3; i++)
      abc[i] = 2;

    for (int i = 0; i < n; i++) {

      cin >> ap[i] >> bp[i] >> cp[i] >> r[i];

      if (r[i] == 1) {
        abc[ap[i]] = 1, abc[bp[i]] = 1, abc[cp[i]] = 1;
      }
    }

    for (int i = 0; i < n; i++) {
      if (abc[ap[i]] == 1 && abc[bp[i]] == 1 && r[i] == 0)
        abc[cp[i]] = 0;
      else if (abc[cp[i]] == 1 && abc[bp[i]] == 1 && r[i] == 0)
        abc[ap[i]] = 0;
      else if (abc[cp[i]] == 1 && abc[ap[i]] == 1 && r[i] == 0)
        abc[bp[i]] = 0;
    }

    for (int i = 1; i < n1 + n2 + n3 + 1; i++)
      cout << abc[i] << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int alist[1005], blist[1005], clist[1005], abc[500], ans[1005];
int A, B, C, n, d, f, g, r, sum;

int main() {

  while (1) {
    alist[10000] = {0};
    blist[10000] = {0};
    clist[10000] = {0};
    abc[10000] = {0};
    ans[10000] = {0};

    cin >> A >> B >> C;
    if (A == 0 && B == 0 && C == 0)
      break;
    cin >> n;

    for (int i = 0; i < n; i++) {
      cin >> d >> f >> g >> r;
      alist[i] = d;
      blist[i] = f;
      clist[i] = g;
      ans[i] = r;
      if (r == 1) {
        abc[d] = 1;
        abc[f] = 1;
        abc[g] = 1;
      } else {
        if (abc[d] != 1)
          abc[d] = 2;
        if (abc[f] != 1)
          abc[f] = 2;
        if (abc[g] != 1)
          abc[g] = 2;
      }
    }

    for (int j = 0; j < 1000; j++) {

      for (int i = 0; i < n; i++) {
        if (abc[alist[i]] == 1 && abc[blist[i]] == 1 && abc[clist[i]] != 1 &&
            ans[i] != 1)
          abc[clist[i]] = 0;
        else if (abc[blist[i]] == 1 && abc[alist[i]] == 1 &&
                 abc[clist[i]] != 1 && ans[i] != 1)
          abc[clist[i]] = 0;
        else if (abc[blist[i]] == 1 && abc[clist[i]] == 1 &&
                 abc[alist[i]] != 1 && ans[i] != 1)
          abc[alist[i]] = 0;
        else if (abc[clist[i]] == 1 && abc[blist[i]] == 1 &&
                 abc[alist[i]] != 1 && ans[i] != 1)
          abc[alist[i]] = 0;
        else if (abc[alist[i]] == 1 && abc[clist[i]] == 1 &&
                 abc[blist[i]] != 1 && ans[i] != 1)
          abc[blist[i]] = 0;
        else if (abc[clist[i]] == 1 && abc[alist[i]] == 1 &&
                 abc[blist[i]] != 1 && ans[i] != 1)
          abc[blist[i]] = 0;
      }
    }

    for (int i = 1; i < A + B + C + 1; i++) {
      cout << abc[i] << endl;
    }
  }

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

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define ZERO(a) memset(a, 0, sizeof(a))
#define AND(x, y) (int)((x) & (y))

const int M = 1024;
int a, b, c, n;
int state[334];
int X[M], Y[M], Z[M];

void init(void) {
  ZERO(state);
  ZERO(X);
  ZERO(Y);
  ZERO(Z);
}

int count1(int i) {
  return (AND(state[X[i]], 1) + AND(state[Y[i]], 1) + AND(state[Z[i]], 1));
}

int main() {
  while (cin >> a >> b >> c && a) {
    init();
    cin >> n;
    rep(i, n) {
      int x, y, z, w;
      cin >> x >> y >> z >> w;
      if (w == 1)
        state[x] = state[y] = state[z] = 1;
      X[i] = x;
      Y[i] = y;
      Z[i] = z;
    }

    rep(i, n) {
      if (count1(i) == 3)
        continue; // w == 1

      if (count1(i) == 2) {
        if (AND(state[X[i]], 1) != 1)
          state[X[i]] = 2;
        if (AND(state[Y[i]], 1) != 1)
          state[Y[i]] = 2;
        if (AND(state[Z[i]], 1) != 1)
          state[Z[i]] = 2;
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      if (state[i] == 0)
        cout << 2 << "\\n";
      if (state[i] == 1)
        cout << 1 << "\\n";
      if (state[i] == 2)
        cout << 0 << "\\n";
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define ZERO(a) memset(a, 0, sizeof(a))
#define AND(x, y) ((x) & (y))

int a, b, c, n;
int state[334];
int memox[120], memoy[120], memoz[120];

void init(void) {
  ZERO(state);
  ZERO(memox);
  ZERO(memoy);
  ZERO(memoz);
}

int main() {
  while (cin >> a >> b >> c && a) {
    init();
    cin >> n;
    rep(i, n) {
      int x, y, z, w;
      cin >> x >> y >> z >> w;
      if (w == 1)
        state[x] = state[y] = state[z] = 1;
      memox[i] = x;
      memoy[i] = y;
      memoz[i] = z;
    }

    rep(i, n) {
      if (AND(AND(state[memox[i]], state[memoy[i]]), memoz[i]) == 1)
        continue;

      // found 1 times 2
      if ((AND(state[memox[i]], 1) + AND(state[memoy[i]], 1) +
           AND(state[memoz[i]], 1)) == 2) {
        if (AND(state[memox[i]], 1) == 0)
          state[memox[i]] = 2;
        if (AND(state[memoy[i]], 1) == 0)
          state[memoy[i]] = 2;
        if (AND(state[memoz[i]], 1) == 0)
          state[memoz[i]] = 2;
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      if (state[i] == 0)
        cout << 2 << endl;
      if (state[i] == 1)
        cout << 1 << endl;
      if (state[i] == 2)
        cout << 0 << endl;
    }
  }

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

#include <cstring>
#include <iostream>
int main() {
  int a, b, c;
  int N;
  while (std::cin >> a >> b >> c, a | b | c) {
    std::cin >> N;
    int data[1024][4];
    int check[301];
    for (int i = 0; i < 301; i++)
      check[i] = 2;
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]);
      if (data[i][3] == 1) {
        check[data[i][0]] = 1;
        check[data[i][1]] = 1;
        check[data[i][2]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int sum = 0;
        if (check[data[i][0]] == 1)
          sum++;
        if (check[data[i][1]] == 1)
          sum++;
        if (check[data[i][2]] == 1)
          sum++;
        if (sum == 2) {
          for (int j = 0; j < 3; j++) {
            if (check[data[i][j]] != 1)
              check[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      printf("%d\\n", check[i + 1]);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
int main() {
  int a, b, c;
  int N;
  while (std::cin >> a >> b >> c, a | b | c) {
    std::cin >> N;
    int data[1024][4];
    int check[128];
    for (int i = 0; i < 101; i++)
      check[i] = 2;
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]);
      if (data[i][3] == 1) {
        check[data[i][0]] = 1;
        check[data[i][1]] = 1;
        check[data[i][2]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int sum = 0;
        if (check[data[i][0]] == 1)
          sum++;
        if (check[data[i][1]] == 1)
          sum++;
        if (check[data[i][2]] == 1)
          sum++;
        if (sum == 2) {
          for (int j = 0; j < 3; j++) {
            if (check[data[i][j]] != 1)
              check[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      printf("%d\\n", check[i + 1]);
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int ans[500];
int a, b, c, N;
int r[1000], x[1000], y[1000], z[1000];
void init() {
  for (int i = 0; i < 500; i++)
    ans[i] = 2;
}
int main() {
  while (cin >> a >> b >> c && a && b && c) {
    init();
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> x[i] >> y[i] >> z[i] >> r[i];
      if (r[i] == 1)
        ans[x[i]] = 1, ans[y[i]] = 1, ans[z[i]] = 1;
    }
    for (int i = 0; i < N; i++) {
      if (r[i] == 1)
        continue;
      if (ans[x[i]] == 1 && ans[y[i]] == 1)
        ans[z[i]] = 0;
      if (ans[y[i]] == 1 && ans[z[i]] == 1)
        ans[x[i]] = 0;
      if (ans[z[i]] == 1 && ans[x[i]] == 1)
        ans[y[i]] = 0;
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int ans[500];
int a, b, c, N;
int r[1000], x[1000], y[1000], z[1000];
void init() {
  for (int i = 0; i < 2000; i++)
    ans[i] = 2;
}
int main() {
  while (cin >> a >> b >> c && a && b && c) {
    init();
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> x[i] >> y[i] >> z[i] >> r[i];
      if (r[i] == 1)
        ans[x[i]] = 1, ans[y[i]] = 1, ans[z[i]] = 1;
    }
    for (int i = 0; i < N; i++) {
      if (r[i] == 1)
        continue;
      if (ans[x[i]] == 1 && ans[y[i]] == 1)
        ans[z[i]] = 0;
      if (ans[y[i]] == 1 && ans[z[i]] == 1)
        ans[x[i]] = 0;
      if (ans[z[i]] == 1 && ans[x[i]] == 1)
        ans[y[i]] = 0;
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
long long int mo[10001], A, B, C, a, b, c, m[10001], ans[1100], n;
int main() {
  while (1) {
    fill(mo, mo + 10000, 0);
    fill(m, m + 10000, 2);
    cin >> a >> b >> c >> n;
    if (a == 0 && b == 0 && c == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> mo[i] >> mo[i + n] >> mo[i + n + n] >> ans[i];
      if (ans[i] == 1) {
        m[mo[i]] = 1;
        m[mo[i + n]] = 1;
        m[mo[i + n + n]] = 1;
      }
    }
    for (int j = 0; j < n; j++) {
      if (m[mo[j]] == 1 && m[mo[j + n]] == 1 && ans[j] == 0) {
        m[mo[j + n + n]] = 0;
      } else if (m[mo[j + n]] == 1 && m[mo[j + n + n]] == 1 && ans[j] == 0) {
        m[mo[j]] = 0;
      } else if (m[mo[j]] == 1 && m[mo[j + n + n]] == 1 && ans[j] == 0) {
        m[mo[j + n]] = 0;
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << m[i] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
long long int mo[1500], A, B, C, a, b, c, m[1500], ans[1100], n;
int main() {
  while (1) {
    fill(mo, mo + 1500, 0);
    fill(m, m + 1500, 2);
    cin >> a >> b >> c >> n;
    if (a == 0 && b == 0 && c == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> mo[i] >> mo[i + n] >> mo[i + n + n] >> ans[i];
      if (ans[i] == 1) {
        m[mo[i]] = 1;
        m[mo[i + n]] = 1;
        m[mo[i + n + n]] = 1;
      }
    }
    for (int j = 0; j < n; j++) {
      if (m[mo[j]] == 1 && m[mo[j + n]] == 1 && ans[j] == 0) {
        m[mo[j + n + n]] = 0;
      } else if (m[mo[j + n]] == 1 && m[mo[j + n + n]] == 1 && ans[j] == 0) {
        m[mo[j]] = 0;
      } else if (m[mo[j]] == 1 && m[mo[j + n + n]] == 1 && ans[j] == 0) {
        m[mo[j + n]] = 0;
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << m[i] << endl;
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(a, b, c) for (int a = b; a < c; a++)
using namespace std;
int con[3003];
int an[1001];
int ans[1001];
int main() {
  while (1) {
    rep(i, 0, 1001) ans[i] = 2;
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;
    int n;
    cin >> n;
    rep(i, 0, n) {
      // int x,y,z,an;
      cin >> con[i] >> con[n + i] >> con[n * 2 + i] >> an[i];
      // x--;y--;z--;
      // cout << i << a+i << a+b+i << endl;
      if (an[i] == 1) {
        ans[con[i]] = 1;
        ans[con[n + i]] = 1;
        ans[con[n * 2 + i]] = 1;
      }
    }
    rep(i, 0, n) {
      // cout << con[i] << con[i+n] << con[i+n+2] << endl;
      if (an[i] == 0)
        if (ans[con[i]] == 1 && ans[con[n + i]] == 1 &&
            ans[con[n * 2 + i]] == 2) {
          ans[con[i + n * 2]] = 0;
        }
      if (an[i] == 0)
        if (ans[con[i]] == 1 && ans[con[n + i]] == 2 &&
            ans[con[n * 2 + i]] == 1) {
          ans[con[i + n]] = 0;
        }
      if (an[i] == 0)
        if (ans[con[i]] == 2 && ans[con[n + i]] == 1 &&
            ans[con[n * 2 + i]] == 1) {
          ans[con[i]] = 0;
        }
    }
    rep(i, 1, a + b + c + 1) { cout << ans[i] << endl; }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(a, b, c) for (int a = b; a < c; a++)
using namespace std;
int con[1001 * 2];
int an[1001];
int ans[1001];
int main() {
  while (1) {
    rep(i, 0, 1001) ans[i] = 2;
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;
    int n;
    cin >> n;
    rep(i, 0, n) {
      // int x,y,z,an;
      cin >> con[i] >> con[n + i] >> con[n * 2 + i] >> an[i];
      // x--;y--;z--;
      // cout << i << a+i << a+b+i << endl;
      if (an[i] == 1) {
        ans[con[i]] = 1;
        ans[con[n + i]] = 1;
        ans[con[n * 2 + i]] = 1;
      }
    }
    rep(i, 0, n) {
      // cout << con[i] << con[i+n] << con[i+n+2] << endl;
      if (an[i] == 0)
        if (ans[con[i]] == 1 && ans[con[n + i]] == 1 &&
            ans[con[n * 2 + i]] == 2) {
          ans[con[i + n * 2]] = 0;
        }
      if (an[i] == 0)
        if (ans[con[i]] == 1 && ans[con[n + i]] == 2 &&
            ans[con[n * 2 + i]] == 1) {
          ans[con[i + n]] = 0;
        }
      if (an[i] == 0)
        if (ans[con[i]] == 2 && ans[con[n + i]] == 1 &&
            ans[con[n * 2 + i]] == 1) {
          ans[con[i]] = 0;
        }
    }
    rep(i, 1, a + b + c + 1) { cout << ans[i] << endl; }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a | b | c) {
    int n;
    cin >> n;

    //??¨???????¨????????????°
    int m = a + b + c;
    //????????????????????????
    vector<int> v(m, 2);

    vector<int> x(n), y(n), z(n), r(n);
    rep(i, n) {
      scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]);
      --x[i];
      --y[i];
      --z[i];
    }

    //????????£?????????????????????????????????????????¨?????£???
    rep(i, n) {
      if (r[i] == 0)
        continue;

      v[x[i]] = 1;
      v[y[i]] = 1;
      v[z[i]] = 1;
    }

    //??????????????????????????????
    rep(t, n) rep(i, n) {
      if (r[i] == 1)
        continue;
      //??????2????????£???(1)??§?¢??????????????????°???????????????(0)

      if (v[x[i]] == 1 && v[y[i]] == 1)
        v[z[i]] = 0;
      if (v[y[i]] == 1 && v[z[i]] == 1)
        v[x[i]] = 0;
      if (v[z[i]] == 1 && v[x[i]] == 1)
        v[y[i]] = 0;
    }

    // output
    rep(i, m) printf("%d\\n", v[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a | b | c) {
    int n;
    cin >> n;

    //??¨???????¨????????????°
    int m = a + b + c;
    //????????????????????????
    vector<int> v(m, 2);

    vector<int> x(m), y(m), z(m), r(m);
    rep(i, n) {
      scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]);
      --x[i];
      --y[i];
      --z[i];
    }

    //????????£?????????????????????????????????????????¨?????£???
    rep(i, n) {
      if (r[i] == 0)
        continue;

      v[x[i]] = 1;
      v[y[i]] = 1;
      v[z[i]] = 1;
    }

    //??????????????????????????????
    rep(t, n) rep(i, n) {
      if (r[i] == 1)
        continue;
      //??????2????????£???(1)??§?¢??????????????????°???????????????(0)

      if (v[x[i]] == 1 && v[y[i]] == 1)
        v[z[i]] = 0;
      if (v[y[i]] == 1 && v[z[i]] == 1)
        v[x[i]] = 0;
      if (v[z[i]] == 1 && v[x[i]] == 1)
        v[y[i]] = 0;
    }

    // output
    rep(i, m) printf("%d\\n", v[i]);
  }
  return 0;
}