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

#include <cstdio>

int main() {
  while (true) {

    int a, b, c, n;
    int test[3000], r[1000];
    int ans[1000];
    scanf("%d%d%d", &a, &b, &c);
    if (a == 0)
      break;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2,
            r + i);
      test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
    }

    for (int i = 0; i < a + b + c; ++i)
      ans[i] = 2;
    for (int i = 0; i < n; ++i) {
      if (r[i] != 1)
        continue;
      for (int j = i * 3; j < i * 3 + 3; ++j)
        ans[test[j]] = 1;
    }
    for (int i = 0; i < n; ++i) {
      if (r[i] != 0)
        continue;
      int correct = 0;
      for (int j = i * 3; j < i * 3 + 3; ++j)
        correct += (ans[test[j]] == 1);
      if (correct != 2)
        continue;
      for (int j = i * 3; j < i * 3 + 3; ++j) {
        if (ans[test[j]] != 1)
          ans[test[j]] = 0;
      }
    }
    for (int i = 0; i < a + b + c; ++i)
      printf("%d\\n", ans[i]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>

int main() {
  while (true) {

    int a, b, c, n;
    int test[3000], r[1000];
    int ans[1000];
    scanf("%d%d%d", &a, &b, &c);
    if (a == 0)
      break;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2,
            r + i);
      test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
    }

    for (int i = 0; i < a + b + c; ++i)
      ans[i] = 2;
    for (int i = 0; i < n; ++i) {
      if (r[i] != 1)
        continue;
      for (int j = i * 3; j < i * 3 + 3; ++j)
        ans[j] = 1;
    }
    for (int i = 0; i < n; ++i) {
      if (r[i] != 0)
        continue;
      int correct = 0;
      for (int j = i * 3; j < i * 3 + 3; ++j)
        correct += (ans[j] == 1);
      if (correct != 2)
        continue;
      for (int j = i * 3; j < i * 3 + 3; ++j) {
        if (ans[j] != 1)
          ans[j] = 0;
      }
    }
    for (int i = 0; i < a + b + c; ++i)
      printf("%d\\n", ans[i]);
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int a, b, c, d, e[1001], f[1001], g[1001], h[1001], x[1001], y[1004], z[1001];
int main(void) {
  while (scanf("%d%d%d", &a, &b, &c), a + b + c) {
    int result[320] = {0};
    scanf("%d", &d);

    for (int i = 0; i < d; i++) {
      scanf("%d%d%d%d", &e[i], &f[i], &g[i], &h[i]);
      if (h[i] == 1) // ok!
      {
        result[e[i] - 1] = 1;
        x[i] = e[i];
        result[f[i] - 1] = 1;
        y[i] = f[i];
        result[g[i] - 1] = 1;
        z[i] = g[i];
      }
    }

    for (int i = 0; i < d; i++) {
      if (h[i] == 0) {
        if (result[f[i] - 1] == 1 && result[g[i] - 1] == 1)
          result[e[i] - 1] = 2;
      }
      if (h[i] == 0) {
        if (result[e[i] - 1] == 1 && result[g[i] - 1] == 1)
          result[f[i] - 1] = 2;
      }
      if (h[i] == 0) {
        if (result[f[i] - 1] == 1 && result[e[i] - 1] == 1)
          result[g[i] - 1] = 2;
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      if (result[i] == 2)
        result[i] = 0;
      else if (result[i] == 0)
        result[i] = 2;
      printf("%d\\n", result[i]);
    }
  }
  return 0;
}

Error: 0

Fixed submission:


#include <stdio.h>
int a, b, c, d, e, f, g, h, x[100], y[100], z[100], result[320] = {2};
int main(void) {
  while (scanf("%d%d%d", &a, &b, &c), a + b + c) {
    scanf("%d", &d);
    for (int i = 0; i < d; i++) {
      scanf("%d%d%d%d", &e, &f, &g, &h);
    }
    for (int i = 0; i < d; i++) {
      if (h == 1) // ok!
      {
        result[e - 1] = 1;
        x[i] = e;
        result[f - 1] = 1;
        y[i] = f;
        result[g - 1] = 1;
        z[i] = g;
      } else {
        if (x[i] != e)
          result[e - 1] = 0;
        if (y[i] != f)
          result[f - 1] = 0;
        if (z[i] != g)
          result[g - 1] = 0;
      }
    }

    for (int i = 0; i < d; i++) {
      if (result[e - 1] == 0) {
        if (result[f - 1] == 1 || result[g - 1] == 1)
          result[e - 1] = 2;
      }
      if (result[f - 1] == 0) {
        if (result[e - 1] == 1 || result[g - 1] == 1)
          result[f - 1] = 2;
      }
      if (result[g - 1] == 0) {
        if (result[f - 1] == 1 || result[e - 1] == 1)
          result[g - 1] = 2;
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      printf("%d\\n", result[i]);
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000][4];
int b[302];
int main() {
  int x, y, z, n, t;
  while (1) {
    scanf("%d%d%d", &x, &y, &z);
    if (!x && !y && !z)
      break;
    scanf("%d", &n);
    fill(b, b + 302, 2);
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
      if (a[i][3])
        b[a[i][0]] = b[a[i][1]] = b[a[i][2]] = 1;
    }
    for (int i = 0; i < n; i++) {
      t = 0;
      if (a[i][3] == 0) {
        rep(j, 3) if (b[a[i][j]] == 1) t++;
        if (t == 2)
          rep(j, 3) if (b[a[i][j]] == 2) b[a[i][j]] = 0;
      }
    }
    rrep(i, x + y + z) printf("%d\\n", b[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000][4];
int b[302];
int main() {
  int x, y, z, n, t;
  while (1) {
    scanf("%d%d%d", &x, &y, &z);
    scanf("%d", &n);
    fill(b, b + 302, 2);
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
      if (a[i][3])
        b[a[i][0]] = b[a[i][1]] = b[a[i][2]] = 1;
    }
    for (int i = 0; i < n; i++) {
      t = 0;
      if (a[i][3] == 0) {
        rep(j, 3) if (b[a[i][j]] == 1) t++;
        if (t == 2)
          rep(j, 3) if (b[a[i][j]] == 2) b[a[i][j]] = 0;
      }
    }
    rrep(i, x + y + z) printf("%d\\n", b[i]);
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "stdio.h"

int parts[3] = {};
int query;
int flag[301] = {};
int first[1000] = {};
int second[1000] = {};
int third[1000] = {};
int result[1000] = {};
int num[3];
int box;
int dif;

int main() {
  scanf("%d %d %d", &parts[0], &parts[1], &parts[2]);
  while (parts[0] != 0) {
    scanf("%d", &query);
    for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++)
      flag[i] = 2;
    for (int i = 0; i < query; i++) {
      scanf("%d %d %d %d", &first[i], &second[i], &third[i], &result[i]);
      if (result[i] == 1) {
        flag[first[i]] = 1;
        flag[second[i]] = 1;
        flag[third[i]] = 1;
      }
    }
    for (int i = 0; i < query; i++) {
      if (result[i] == 0) {
        box = 0;
        if (flag[first[i]] == 1)
          box++;
        if (flag[second[i]] == 1)
          box++;
        if (flag[third[i]] == 1)
          box++;
        if (box == 2) {
          if (flag[first[i]] == 2)
            flag[first[i]] = 0;
          if (flag[second[i]] == 2)
            flag[second[i]] = 0;
          if (flag[third[i]] == 2)
            flag[third[i]] = 0;
        }
      }
    }
    for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++) {
      printf("%d\\n", flag[i]);
    }
    scanf("%d %d %d", &parts[0], &parts[1], &parts[2]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "stdio.h"

int parts[3] = {};
int query;
int flag[301] = {};
int first[1000] = {};
int second[1000] = {};
int third[1000] = {};
int result[1000] = {};
int num[3];
int box;
int dif;

int main() {
  scanf("%d %d %d %d", &parts[0], &parts[1], &parts[2], &query);
  while (query != 0) {
    for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++)
      flag[i] = 2;
    for (int i = 0; i < query; i++) {
      scanf("%d %d %d %d", &first[i], &second[i], &third[i], &result[i]);
      if (result[i] == 1) {
        flag[first[i]] = 1;
        flag[second[i]] = 1;
        flag[third[i]] = 1;
      }
    }
    for (int i = 0; i < query; i++) {
      if (result[i] == 0) {
        box = 0;
        if (flag[first[i]] == 1)
          box++;
        if (flag[second[i]] == 1)
          box++;
        if (flag[third[i]] == 1)
          box++;
        if (box == 2) {
          if (flag[first[i]] == 2)
            flag[first[i]] = 0;
          if (flag[second[i]] == 2)
            flag[second[i]] = 0;
          if (flag[third[i]] == 2)
            flag[third[i]] = 0;
        }
      }
    }
    for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++) {
      printf("%d\\n", flag[i]);
    }
    scanf("%d %d %d %d", &parts[0], &parts[1], &parts[2], &query);
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  int n;

  int d[1001];
  int e[1001];
  int f[1001];
  int g[1001];

  int flg[301];
  while (1) {
    scanf("%d%d%d", &a, &b, &c);
    if (a == 0) {
      break;
    }
    scanf("%d", &n);
    for (int i = 0; i < 301; i++) {
      flg[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &d[i], &e[i], &f[i], &g[i]);
      if (g[i] == 1) {
        flg[d[i]] = 1;
        flg[e[i]] = 1;
        flg[f[i]] = 1;
      }
    }

    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < n; i++) {
        if (g[i] != 0) {
          continue;
        }
        if (flg[d[i]] == 2 && flg[e[i]] == 1 && flg[f[i]] == 1) {
          flg[d[i]] = 0;
        } else if (flg[d[i]] == 1 && flg[e[i]] == 2 && flg[f[i]] == 1) {
          flg[e[i]] = 0;
        } else if (flg[d[i]] == 1 && flg[e[i]] == 1 && flg[f[i]] == 2) {
          flg[f[i]] = 0;
        }
      }
    }

    for (int i = 1; i < a + b + c + 1; i++) {
      printf("%d\\n", flg[i]);
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  int n;

  int d[1001];
  int e[1001];
  int f[1001];
  int g[1001];

  int flg[101];
  while (1) {
    scanf("%d%d%d", &a, &b, &c);
    if (a == 0) {
      break;
    }
    scanf("%d", &n);
    for (int i = 0; i < 101; i++) {
      flg[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &d[i], &e[i], &f[i], &g[i]);
      if (g[i] == 1) {
        flg[d[i]] = 1;
        flg[e[i]] = 1;
        flg[f[i]] = 1;
      }
    }

    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < n; i++) {
        if (g[i] != 0) {
          continue;
        }
        if (flg[d[i]] == 2 && flg[e[i]] == 1 && flg[f[i]] == 1) {
          flg[d[i]] = 0;
        } else if (flg[d[i]] == 1 && flg[e[i]] == 2 && flg[f[i]] == 1) {
          flg[e[i]] = 0;
        } else if (flg[d[i]] == 1 && flg[e[i]] == 1 && flg[f[i]] == 2) {
          flg[f[i]] = 0;
        }
      }
    }

    for (int i = 1; i < a + b + c + 1; i++) {
      printf("%d\\n", flg[i]);
    }
  }
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct check {
  int i, j, k;
  check(int x, int y, int z) {
    i = x;
    j = y;
    k = z;
  }
};
int main() {
  int res[301], a, i, j, k, r, n;
  for (; cin >> a >> i >> j >> n;) {
    a += i + j;
    fill(res, res + 301, 2);
    vector<check> fails;
    for (; n--;) {
      cin >> i >> j >> k >> r;
      if (r)
        res[i] = res[j] = res[k] = 1;
      else
        fails.push_back(check(i, j, k));
    }
    vector<check>::iterator it;
    for (it = fails.begin(); it != fails.end(); ++it) {
      k = (res[it->i] == 1) + (res[it->j] == 1) + (res[it->k] == 1);
      if (k == 2) {
        if (res[it->i] != 1)
          res[it->i] = 0;
        if (res[it->j] != 1)
          res[it->j] = 0;
        if (res[it->k] != 1)
          res[it->k] = 0;
      }
    }
    for (i = 0; i++ < a;)
      cout << res[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct check {
  int i, j, k;
  check(int x, int y, int z) {
    i = x;
    j = y;
    k = z;
  }
};
int main() {
  int res[101], a, i, j, k, r, n;
  for (; cin >> a >> i >> j >> n;) {
    a += i + j;
    fill(res, res + 101, 2);
    vector<check> fails;
    for (; n--;) {
      cin >> i >> j >> k >> r;
      if (r)
        res[i] = res[j] = res[k] = 1;
      else
        fails.push_back(check(i, j, k));
    }
    vector<check>::iterator it;
    for (it = fails.begin(); it != fails.end(); ++it) {
      k = (res[it->i] == 1) + (res[it->j] == 1) + (res[it->k] == 1);
      if (k == 2) {
        if (res[it->i] != 1)
          res[it->i] = 0;
        if (res[it->j] != 1)
          res[it->j] = 0;
        if (res[it->k] != 1)
          res[it->k] = 0;
      }
    }
    for (i = 0; i++ < a;)
      cout << res[i] << endl;
  }
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

    int q[350];
    for (int i = 0; i < a + b + c; i++)
      q[i] = 2;
    int n;
    cin >> n;
    int z = 0;
    int ls[1200][5];

    for (int i = 0; i < n; i++) {
      int d, e, f, g;
      cin >> d >> e >> f >> g;
      if (g == 0) {
        ls[z][0] = d;
        ls[z][1] = e;
        ls[z][2] = f;
        z++;
      }

      else {
        q[d - 1] = 1;
        q[e - 1] = 1;
        q[f - 1] = 1;
      }
    }

    for (int i = 0; i < z; i++) {
      int d = 0, e = 0, f = 0;
      if (q[ls[i][0] - 1] == 1)
        d = 1;
      if (q[ls[i][1] - 1] == 1)
        e = 1;
      if (q[ls[i][2] - 1] == 1)
        f = 1;

      if (d == 1 && e == 1) {
        q[ls[i][2] - 1] = 0;
      }
      if (d == 1 && f == 1) {
        q[ls[i][1] - 1] = 0;
      }
      if (e == 1 && f == 1) {
        q[ls[i][0] - 1] = 0;
      }
    }

    for (int i = 0; i < a + b + c; i++) {
      cout << q[i] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

    int q[350];
    for (int i = 0; i < a + b + c; i++)
      q[i] = 2;
    int n;
    cin >> n;
    int z = 0;
    int ls[350][3];

    for (int i = 0; i < n; i++) {
      int d, e, f, g;
      cin >> d >> e >> f >> g;
      if (g == 0) {
        ls[z][0] = d;
        ls[z][1] = e;
        ls[z][2] = f;
        z++;
      }

      else {
        q[d - 1] = 1;
        q[e - 1] = 1;
        q[f - 1] = 1;
      }
    }

    for (int i = 0; i < z; i++) {
      int d = 0, e = 0, f = 0;
      if (q[ls[i][0] - 1] == 1)
        d = 1;
      if (q[ls[i][1] - 1] == 1)
        e = 1;
      if (q[ls[i][2] - 1] == 1)
        f = 1;

      if (d == 1 && e == 1) {
        q[ls[i][2] - 1] = 0;
      }
      if (d == 1 && f == 1) {
        q[ls[i][1] - 1] = 0;
      }
      if (e == 1 && f == 1) {
        q[ls[i][0] - 1] = 0;
      }
    }

    for (int i = 0; i < a + b + c; i++) {
      cout << q[i] << endl;
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main(void) {

  int a, b, c;
  int N;

  int parts[512];

  int experiments[1024][4];

  unsigned char judge = 0;

  while (true) {
    scanf("%d%d%d", &a, &b, &c);
    if ((a == 0) || (b == 0) || (c == 0))
      break;
    scanf("%d", &N);
    for (int i = 0; i < 512; i++) {
      parts[i] = 2;
    }
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", experiments[i], experiments[i] + 1, experiments[i] + 2,
            experiments[i] + 3);
      if (experiments[i][3] == 1) {
        parts[experiments[i][0]] = 1;
        parts[experiments[i][1]] = 1;
        parts[experiments[i][2]] = 1;
      }
    }
    /*for(int i=0;i<N;i++){
            printf("###%d%d%d%d\\n",experiments[i][0],experiments[i][1],experiments[i][2],experiments[i][3]);
    }*/
    for (int i = 0; i < N; i++) {
      judge = 0;
      if (experiments[i][3] == 0) {
        judge |= (parts[experiments[i][0]] != 1 ? 0x1 : 0x0);
        judge |= (parts[experiments[i][1]] != 1 ? 0x2 : 0x0);
        judge |= (parts[experiments[i][2]] != 1 ? 0x4 : 0x0);
        switch (judge) {
        case 0x1:
          parts[experiments[i][0]] = 0;
          break;
        case 0x2:
          parts[experiments[i][1]] = 0;
          break;
        case 0x4:
          parts[experiments[i][2]] = 0;
          break;
        }
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      printf("%d\\n", parts[i]);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main(void) {

  int a, b, c;
  int N;

  int parts[128];

  int experiments[1024][4];

  unsigned char judge = 0;

  while (true) {
    scanf("%d%d%d", &a, &b, &c);
    if ((a == 0) || (b == 0) || (c == 0))
      break;
    scanf("%d", &N);
    for (int i = 0; i < 128; i++) {
      parts[i] = 2;
    }
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", experiments[i], experiments[i] + 1, experiments[i] + 2,
            experiments[i] + 3);
      if (experiments[i][3] == 1) {
        parts[experiments[i][0]] = 1;
        parts[experiments[i][1]] = 1;
        parts[experiments[i][2]] = 1;
      }
    }
    /*for(int i=0;i<N;i++){
            printf("###%d%d%d%d\\n",experiments[i][0],experiments[i][1],experiments[i][2],experiments[i][3]);
    }*/
    for (int i = 0; i < N; i++) {
      judge = 0;
      if (experiments[i][3] == 0) {
        judge |= (parts[experiments[i][0]] != 1 ? 0x1 : 0x0);
        judge |= (parts[experiments[i][1]] != 1 ? 0x2 : 0x0);
        judge |= (parts[experiments[i][2]] != 1 ? 0x4 : 0x0);
        switch (judge) {
        case 0x1:
          parts[experiments[i][0]] = 0;
          break;
        case 0x2:
          parts[experiments[i][1]] = 0;
          break;
        case 0x4:
          parts[experiments[i][2]] = 0;
          break;
        }
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      printf("%d\\n", parts[i]);
    }
  }

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

#include <cstdio>

using namespace std;

int main() {
  int a, b, c, n, total, kind;
  int rist[1000][3], ristsize;
  int isacheced[301];

  scanf("%d %d %d", &a, &b, &c);

  while (a != 0 && b != 0 && c != 0) {
    scanf("%d", &n);

    total = a + b + c;
    ristsize = 0;
    for (int i = 0; i <= total; i++) {
      isacheced[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &kind);
      if (kind == 1) {
        isacheced[a] = 1;
        isacheced[b] = 1;
        isacheced[c] = 1;
      } else {
        rist[ristsize][0] = a;
        rist[ristsize][1] = b;
        rist[ristsize][2] = c;
        ristsize++;
      }
    }

    for (int i = 0; i < ristsize; i++) {
      if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) {
        isacheced[rist[i][2]] = 0;
      } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][0]] = 0;
      } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][1]] = 0;
      }
    }

    for (int i = 1; i <= total; i++) {
      printf("%d\\n", isacheced[i]);
    }

    scanf("%d %d %d", &a, &b, &c);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

using namespace std;

int main() {
  int a, b, c, n, total, kind;
  int rist[1000][3], ristsize;
  int isacheced[101];

  scanf("%d %d %d", &a, &b, &c);

  while (a != 0 && b != 0 && c != 0) {
    scanf("%d", &n);

    total = a + b + c;
    ristsize = 0;
    for (int i = 0; i <= total; i++) {
      isacheced[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &kind);
      if (kind == 1) {
        isacheced[a] = 1;
        isacheced[b] = 1;
        isacheced[c] = 1;
      } else {
        rist[ristsize][0] = a;
        rist[ristsize][1] = b;
        rist[ristsize][2] = c;
        ristsize++;
      }
    }

    for (int i = 0; i < ristsize; i++) {
      if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) {
        isacheced[rist[i][2]] = 0;
      } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][0]] = 0;
      } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][1]] = 0;
      }
    }

    for (int i = 1; i <= total; i++) {
      printf("%d\\n", isacheced[i]);
    }

    scanf("%d %d %d", &a, &b, &c);
  }

  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

vector<int> ans;

bool check(vector<int> v) {
  int count = 0, no;

  for (int i = 0; i < 3; ++i)
    if (ans[v[i]] != 1) {
      no = v[i];
      ++count;
    }

  if (count > 1)
    return false;
  else if (count == 0) {
    cout << "ERROR" << endl;
    return false;
  } else
    ans[no] = 0;

  return true;
}

vector<int> make_result(int a, int b, int c, int r) {
  vector<int> ret;

  ret.push_back(a);
  ret.push_back(b);
  ret.push_back(c);
  ret.push_back(r);

  return ret;
}

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    int n = a + b + c;
    int N;
    cin >> N;
    ans.erase(ans.begin(), ans.end());

    for (int i = 0; i < n; ++i)
      ans.push_back(2);

    vector<vector<int>> results;
    for (int i = 0; i < N; ++i) {
      int r;
      cin >> a >> b >> c >> r;
      --a, --b, --c;

      if (r == 1)
        ans[a] = ans[b] = ans[c] = 1;

      else
        results.push_back(make_result(a, b, c, r));
    }

    bool update = false;
    for (int i = 0; i < results.size(); ++i)
      if (update = check(results[i]))
        results.erase(results.begin() + i, results.begin() + i);

    for (int i = 0; i < n; ++i)
      cout << ans[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

vector<int> ans;

bool check(vector<int> v) {
  int count = 0, no;

  for (int i = 0; i < 3; ++i)
    if (ans[v[i]] != 1) {
      no = v[i];
      ++count;
    }

  if (count > 1)
    return false;
  else if (count == 0) {
    cout << "ERROR" << endl;
    return false;
  } else
    ans[no] = 0;

  return true;
}

vector<int> make_result(int a, int b, int c, int r) {
  vector<int> ret;

  ret.push_back(a);
  ret.push_back(b);
  ret.push_back(c);
  ret.push_back(r);

  return ret;
}

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    int n = a + b + c;
    int N;
    cin >> N;
    ans.erase(ans.begin(), ans.end());

    for (int i = 0; i < n; ++i)
      ans.push_back(2);

    vector<vector<int>> results;
    for (int i = 0; i < N; ++i) {
      int r;
      cin >> a >> b >> c >> r;
      --a, --b, --c;

      if (r == 1)
        ans[a] = ans[b] = ans[c] = 1;

      else
        results.push_back(make_result(a, b, c, r));
    }

    while (1) {
      bool update = false;
      for (int i = 0; i < results.size(); ++i)
        if (update = check(results[i]))
          results.erase(results.begin() + i, results.begin() + i);

      if (!update)
        break;
    }

    for (int i = 0; i < n; ++i)
      cout << ans[i] << endl;
  }
}