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

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

#define loop(i, n) for (int i = 1; i <= n; i++)
struct test {
  int i, j, k;
};

vector<test> t;
int p[302];

int main() {
  int a, b, c, n, i, j, k, r;
  while (cin >> a >> b >> c) {
    cin >> n;
    t.clear();
    loop(i, a + b + c) p[i] = 2;
    loop(h, n) {
      cin >> i >> j >> k >> r;
      if (r == 1) {
        p[i] = p[j] = p[k] = 1;
      } else {
        t.push_back({i, j, k});
      }
    }
    for (int h = 0; h < t.size(); h++) {
      i = t[h].i;
      j = t[h].j;
      k = t[h].k;
      if (p[i] == 1 && p[j] == 1) {
        p[k] = 0;
      } else if (p[j] == 1 && p[k] == 1) {
        p[i] = 0;
      } else if (p[k] == 1 && p[i] == 1) {
        p[j] = 0;
      }
    }
    loop(i, a + b + c) cout << p[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define loop(i, n) for (int i = 1; i <= n; i++)
struct test {
  int i, j, k;
};

vector<test> t;
int p[302];

int main() {
  int a, b, c, n, i, j, k, r;
  while (cin >> a >> b >> c) {
    cin >> n;
    t.clear();
    loop(i, a + b + c) p[i] = 2;
    loop(h, n) {
      cin >> i >> j >> k >> r;
      if (r == 1) {
        p[h] = p[h] = p[h] = 1;
      } else {
        t.push_back({i, j, k});
      }
    }
    for (int h = 0; h < t.size(); h++) {
      i = t[h].i;
      j = t[h].j;
      k = t[h].k;
      if (p[i] == 1 && p[j] == 1) {
        p[k] = 0;
      } else if (p[j] == 1 && p[k] == 1) {
        p[i] = 0;
      } else if (p[k] == 1 && p[i] == 1) {
        p[j] = 0;
      }
    }
    loop(i, a + b + c) cout << p[i] << endl;
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <vector>

struct Res {
  int i, j, k, r;
};

int data[310];
std::vector<Res> v;

int main() {
  while (true) {
    for (int i = 0; i < 310; i++)
      data[i] = 2;
    v.clear();

    int a, b, c;
    int n;

    scanf("%d %d %d", &a, &b, &c);
    if (a == 0 && b == 0 && c == 0)
      break;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
      Res r;
      scanf("%d %d %d %d", &r.i, &r.j, &r.k, &r.r);
      if (r.r == 1)
        data[r.i] = 1, data[r.j] = 1, data[r.k] = 1;
      else
        v.push_back(r);
    }

    for (int i = 0; i < v.size(); i++) {
      if (data[v[i].i] == 1 && data[v[i].j] == 1)
        data[v[i].k] = 0;
      if (data[v[i].i] == 1 && data[v[i].k] == 1)
        data[v[i].j] = 0;
      if (data[v[i].j] == 1 && data[v[i].k] == 1)
        data[v[i].i] = 0;
    }

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

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>

struct Res {
  int i, j, k, r;
};

int data[310];
std::vector<Res> v;

int main() {
  while (true) {
    for (int i = 0; i < 303; i++)
      data[i] = 2;

    int a, b, c;
    int n;

    scanf("%d %d %d %d", &a, &b, &c);
    if (a == 0 && b == 0 && c == 0)
      break;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
      Res r;
      scanf("%d %d %d %d", &r.i, &r.j, &r.k, &r.r);
      if (r.r == 1)
        data[r.i] = 1, data[r.j] = 1, data[r.k] = 1;
      else
        v.push_back(r);
    }

    for (int i = 0; i < v.size(); i++) {
      if (data[v[i].i] == 1 && data[v[i].j] == 1)
        data[v[i].k] = 0;
      if (data[v[i].i] == 1 && data[v[i].k] == 1)
        data[v[i].j] = 0;
      if (data[v[i].j] == 1 && data[v[i].k] == 1)
        data[v[i].i] = 0;
    }

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int a, b, c, N;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;

    int data[1002][5], cmp[303];
    for (int i = 1; i <= a + b + c; i++) {
      cmp[i] = 2;
    }
    cin >> N;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 4; j++) {
        cin >> data[i][j];
      }
      if (data[i][3] == 1) {
        for (int k = 0; k < 3; k++) {
          cmp[data[i][k]] = 1;
        }
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
          if (cmp[data[i][j]] == 1)
            cnt++;
        }
        if (cnt == 2) {
          for (int j = 0; j < 3; j++) {
            if (cmp[data[i][j]] != 1)
              cmp[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << cmp[i] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int a, b, c, N;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;

    int data[1001][5], cmp[302];
    for (int i = 1; i <= a + b + c; i++) {
      cmp[i] = 2;
    }
    cin >> N;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 4; j++) {
        cin >> data[i][j];
        if (data[i][3] == 1) {
          for (int j = 0; j < 3; j++) {
            cmp[data[i][j]] = 1;
          }
        }
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
          if (cmp[data[i][j]] == 1)
            cnt++;
        }
        if (cnt == 2) {
          for (int j = 0; j < 3; j++) {
            if (cmp[data[i][j]] != 1)
              cmp[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      cout << cmp[i] << endl;
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
struct result {
  int A, B, C, R;
};
int a, b, c, N, P[300];
result Res[1000];
int main(int argc, char const *argv[]) {
  while (scanf("%d %d %d", &a, &b, &c), a) {
    memset(P, 0, sizeof(P));
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
      int A, B, C, R;
      scanf("%d %d %d %d", &A, &B, &C, &R);
      Res[i].A = A - 1;
      Res[i].B = B - 1;
      Res[i].C = C - 1;
      Res[i].R = R;
    }
    for (int i = 0; i < N; i++) {
      if (Res[i].R) {
        P[Res[i].A] = P[Res[i].B] = P[Res[i].C] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (!Res[i].R) {
        if (P[Res[i].A] == 1 && P[Res[i].B] == 1)
          P[Res[i].C] = 2;
        if (P[Res[i].A] == 1 && P[Res[i].C] == 1)
          P[Res[i].B] = 2;
        if (P[Res[i].B] == 1 && P[Res[i].C] == 1)
          P[Res[i].A] = 2;
      }
    }
    for (int i = 0; i < (a + b + c); i++) {
      if (P[i] == 2)
        printf("0\\n");
      if (P[i] == 1)
        printf("1\\n");
      if (P[i] == 0)
        printf("2\\n");
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
struct result {
  int A, B, C, R;
};
int a, b, c, N, P[300];
result Res[1000];
int main(int argc, char const *argv[]) {
  while (scanf("%d %d %d %d", &a, &b, &c), a) {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
      int A, B, C, R;
      scanf("%d %d %d %d", &A, &B, &C, &R);
      Res[i].A = A - 1;
      Res[i].B = B - 1;
      Res[i].C = C - 1;
      Res[i].R = R;
    }
    for (int i = 0; i < N; i++) {
      if (Res[i].R) {
        P[Res[i].A] = P[Res[i].B] = P[Res[i].C] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (!Res[i].R) {
        if (P[Res[i].A] == 1 && P[Res[i].B] == 1)
          P[Res[i].C] = 2;
        if (P[Res[i].A] == 1 && P[Res[i].C] == 1)
          P[Res[i].B] = 2;
        if (P[Res[i].B] == 1 && P[Res[i].C] == 1)
          P[Res[i].A] = 2;
      }
    }
    for (int i = 0; i < (a + b + c); i++) {
      if (P[i] == 2)
        printf("0\\n");
      if (P[i] == 1)
        printf("1\\n");
      if (P[i] == 0)
        printf("2\\n");
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(I, X, Y) for (long int I = X; I < Y; I++)
#define REP(I, X) for (long int I = X; I >= 0; I--)
#define INF 1e9 + 7
using namespace std;

int main() {
  int a, b, c;
  vector<int> ans;
  while (1) {
    cin >> a >> b >> c;
    if (!(a || b || c))
      break;
    int N, i, j, k, l;
    cin >> N;
    set<int> unbroken;
    set<int> broken;
    int ii[N], jj[N], kk[N], ll[N];
    FOR(i, 0, N) cin >> ii[i] >> jj[i] >> kk[i] >> ll[i];
    FOR(count1, 0, N) FOR(count2, 0, N) {
      int i = ii[count2], j = jj[count2], k = kk[count2], l = ll[count2];
      if (l) {
        unbroken.insert(i);
        unbroken.insert(j);
        unbroken.insert(k);
      } else {
        if (unbroken.count(i) && unbroken.count(j))
          broken.insert(k);
        if (unbroken.count(j) && unbroken.count(k))
          broken.insert(i);
        if (unbroken.count(k) && unbroken.count(i))
          broken.insert(j);
      }
    }
    FOR(i, 1, a + b + c + 1) {
      if (unbroken.count(i))
        ans.push_back(1);
      else if (broken.count(i))
        ans.push_back(0);
      else
        ans.push_back(2);
    }
  }
  for (auto x : ans)
    cout << x << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(I, X, Y) for (long int I = X; I < Y; I++)
#define REP(I, X) for (long int I = X; I >= 0; I--)
#define INF 1e9 + 7
using namespace std;

int main() {
  int a, b, c;
  vector<int> ans;
  while (1) {
    cin >> a >> b >> c;
    if (!a)
      break;
    int N, i, j, k, l;
    cin >> N;
    set<int> unbroken;
    set<int> broken;
    int ii[N], jj[N], kk[N], ll[N];
    FOR(i, 0, N) cin >> ii[i] >> jj[i] >> kk[i] >> ll[i];
    FOR(count1, 0, N)
    FOR(count1, 0, N) FOR(count2, 0, N) {
      int i = ii[count2], j = jj[count2], k = kk[count2], l = ll[count2];
      if (l) {
        unbroken.insert(i);
        unbroken.insert(j);
        unbroken.insert(k);
      } else {
        if (unbroken.count(i) && unbroken.count(j))
          broken.insert(k);
        if (unbroken.count(j) && unbroken.count(k))
          broken.insert(i);
        if (unbroken.count(k) && unbroken.count(i))
          broken.insert(j);
      }
    }
    FOR(i, 1, a + b + c + 1) {
      if (unbroken.count(i))
        ans.push_back(1);
      else if (broken.count(i))
        ans.push_back(0);
      else
        ans.push_back(2);
    }
  }
  for (auto x : ans)
    cout << x << endl;
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int a, b, c;
  int A[1001], B[1001], C[1001], D[1001];
  int ans[10001];
  int n;
  while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) {
    cin >> n;
    for (int i = 1; i <= a + b + c; i++) {
      ans[i] = 2;
    }
    for (int i = 0; i < n; i++) {
      cin >> A[i] >> B[i] >> C[i] >> D[i];
      if (D[i] == 1) {
        ans[A[i]] = ans[B[i]] = ans[C[i]] = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      if (D[i] == 0) {
        if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1)
          ans[A[i]] = 0;
        if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1)
          ans[B[i]] = 0;
        if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2)
          ans[C[i]] = 0;
      }
    }
    for (int i = 1; i <= a + b + c; i++)
      cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int a, b, c;
  int A[101], B[101], C[101], D[101];
  int ans[301];
  int n;
  while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) {
    cin >> n;
    for (int i = 1; i <= a + b + c; i++) {
      ans[i] = 2;
    }
    for (int i = 0; i < n; i++) {
      cin >> A[i] >> B[i] >> C[i] >> D[i];
      if (D[i] == 1) {
        ans[A[i]] = ans[B[i]] = ans[C[i]] = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      if (D[i] == 0) {
        if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1)
          ans[A[i]] = 0;
        if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1)
          ans[B[i]] = 0;
        if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2)
          ans[C[i]] = 0;
      }
    }
    for (int i = 1; i <= a + b + c; i++)
      cout << ans[i] << endl;
  }
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;
int main(void) {
  int a[1000], b[1000], c[1000], i, j, r[1000], n, ans[303], abc;
  for (j = 0; j < 6; j++) {
    scanf("%d%d%d%d", &a[0], &b[0], &c[0], &n);
    if (a[0] == 0)
      return 0;
    abc = a[0] + b[0] + c[0];
    for (i = 0; i <= abc + 1; i++)
      ans[i] = 2;
    for (i = 0; i < n; i++)
      scanf("%d%d%d%d", &a[i], &b[i], &c[i], &r[i]);
    for (i = 0; i < n; i++)
      if (r[i]) {
        ans[a[i]] = ans[b[i]] = ans[c[i]] = 1;
      }
    for (i = 0; i < n; i++)
      if (r[i] - 1)
        if (ans[a[i]] + ans[b[i]] + ans[c[i]] == 4 &&
            (ans[a[i]] == 1 || ans[b[i]] == 1)) {
          if (ans[a[i]] - 1) {
            ans[a[i]] = 0;
          } else if (ans[b[i]] - 1) {
            ans[b[i]] = 0;
          } else
            ans[c[i]] = 0;
        }
    for (i = 1; i <= abc; i++)
      printf("%d\\n", ans[i]);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;
int main(void) {
  int a[100], b[100], c[100], i, j, r[100], n, ans[303], abc;
  for (j = 0; j < 6; j++) {
    scanf("%d%d%d%d", &a[0], &b[0], &c[0], &n);
    if (a == 0)
      return 0;
    abc = a[0] + b[0] + c[0];
    for (i = 1; i <= abc; i++)
      ans[i] = 2;
    for (i = 0; i < n; i++)
      scanf("%d%d%d%d", &a[i], &b[i], &c[i], &r[i]);
    for (i = 0; i < n; i++)
      if (r[i]) {
        ans[a[i]] = ans[b[i]] = ans[c[i]] = 1;
      }
    for (i = 0; i < n; i++)
      if (r[i] - 1)
        if (ans[a[i]] + ans[b[i]] + ans[c[i]] == 4 &&
            (ans[a[i]] == 1 || ans[b[i]] == 1)) {
          if (ans[a[i]] - 1) {
            ans[a[i]] = 0;
          } else if (ans[b[i]] - 1) {
            ans[b[i]] = 0;
          } else
            ans[c[i]] = 0;
        }
    for (i = 1; i <= abc; i++)
      printf("%d\\n", ans[i]);
  }
}
Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    int n, parts[500], input[10000][4], bd;
    for (int i = 0; i < 500; i++)
      parts[i] = 2;
    cin >> n;
    for (int _i = 0; _i < n; _i++) {
      for (int _j = 0; _j < 4; _j++) {
        cin >> input[_i][_j];
      }
      if (input[_i][3] == 1) {
        for (int i = 0; i < 3; i++) {
          parts[input[_i][i]] = 1;
        }
      }
      for (int i = 0; i <= _i; i++) {
        if (input[i][3] == 1)
          continue;
        bd = -1;
        for (int j = 0; j < 3; j++) {
          if (parts[input[i][j]] == 2 && bd == -1)
            bd = input[i][j];
          else if (parts[input[i][j]] != 1) {
            bd = -1;
            break;
          }
        }
        if (bd != -1)
          parts[bd] = 0;
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      printf("%d\\n", parts[i]);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    int n, parts[301], input[1000][4], bd;
    for (int i = 0; i <= 300; i++)
      parts[i] = 2;
    cin >> n;
    for (int _i = 0; _i < n; _i++) {
      for (int _j = 0; _j < 4; _j++) {
        cin >> input[_i][_j];
        if (input[_i][3] == 1) {
          for (int i = 0; i < 3; i++) {
            parts[input[_i][i]] = 1;
          }
        }
        for (int i = 0; i <= _i; i++) {
          if (input[i][3] == 1)
            continue;
          bd = -1;
          for (int j = 0; j < 3; j++) {
            if (parts[input[i][j]] == 2 && bd == -1)
              bd = input[i][j];
            else if (parts[input[i][j]] != 1) {
              bd = -1;
              break;
            }
          }
          if (bd != -1)
            parts[bd] = 0;
        }
      }
    }
    for (int i = 1; i <= a + b + c; i++) {
      printf("%d\\n", parts[i]);
    }
  }
  return 0;
}
Problem p00437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, c, n, ch[1000][4], good[301] = {0}, sum, ans;

  while (1) {

    for (int i = 0; i < 301; i++) {
      good[i] = 0;
    }

    sum = ans = 0;

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

    if (a + b + c == 0)
      break;

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 4; j++) {
        scanf("%d", &ch[i][j]);
      }
    }

    for (int i = 0; i < n; i++) {
      if (ch[i][3] == 1) {
        for (int j = 0; j < 3; j++) {
          good[ch[i][j]] = 1;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      sum = 0;
      for (int j = 0; j < 3; j++)
        sum += good[ch[i][j]];
      if (sum == 2) {
        for (int j = 0; j < 3; j++)
          if (good[ch[i][j]] != 1) {
            good[ch[i][j]] = -1;
          }
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      if (good[i] == -1)
        ans = 0;
      else if (good[i] == 1)
        ans = 1;
      else
        ans = 2;
      printf("%d\\n", ans);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, c, st[4], n, ch[1000][4], good[301] = {0}, sum, ans;

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

    if (a + b + c == 0)
      break;

    scanf("%d", &n);

    st[0] = 1;
    st[1] = a;
    st[2] = a + b;
    st[3] = a + b + c;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 4; j++) {
        scanf("%d", &ch[i][j]);
      }
    }

    for (int i = 0; i < n; i++) {
      if (ch[i][3] == 1) {
        for (int j = 0; j < 3; j++) {
          good[ch[i][j]] = 1;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      sum = 0;
      for (int j = 0; j < 3; j++)
        sum += good[ch[i][j]];
      if (sum == 2) {
        for (int j = 0; j < 3; j++)
          if (good[ch[i][j]] != 1) {
            good[ch[i][j]] = -1;
          }
      }
    }

    for (int i = 1; i <= a + b + c; i++) {
      if (good[i] == -1)
        ans = 0;
      else if (good[i] == 1)
        ans = 1;
      else
        ans = 2;
      printf("%d\\n", ans);
    }
  }

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


#include <bits/stdc++.h>
using namespace std;
int a, b, c, N, buhin[500], mei[2000][5], karibuhin[500];
int main() {
  while (1) {
    fill(buhin, buhin + 400, 2);
    int fl = 1;
    cin >> a >> b >> c;
    if (a + b + c == 0)
      break;
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> mei[i][0] >> mei[i][1] >> mei[i][2] >> mei[i][3];
      mei[i][0]--;
      mei[i][1]--;
      mei[i][2]--;
    }
    while (1) {
      for (int f = 0; f < a + b + c; f++) {
        karibuhin[f] = buhin[f];
      }
      if (fl == 0)
        break;
      fl = 0;
      for (int i = 0; i < N; i++) {
        if (mei[i][3] == 1) {
          buhin[mei[i][0]] = 1;
          buhin[mei[i][1]] = 1;
          buhin[mei[i][2]] = 1;
        } else if (mei[i][3] == 0) {
          if (buhin[mei[i][0]] == 1 && buhin[mei[i][1]] == 1) {
            buhin[mei[i][2]] = 0;
          }
          if (buhin[mei[i][1]] == 1 && buhin[mei[i][2]] == 1) {
            buhin[mei[i][0]] = 0;
          }
          if (buhin[mei[i][2]] == 1 && buhin[mei[i][0]] == 1) {
            buhin[mei[i][1]] = 0;
          }
        }
        for (int f = 0; f < a + b + c; f++) {
          if (karibuhin[f] != buhin[f]) {
            fl++;
          }
        }
      }
    }
    for (int lk = 0; lk < a + b + c; lk++) {
      cout << buhin[lk] << endl;
    }
  }
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
int a, b, c, N, buhin[105], mei[1010][5], karibuhin[105];
int main() {
  while (1) {
    fill(buhin, buhin + 105, 2);
    int fl = 1;
    cin >> a >> b >> c;
    if (a + b + c == 0)
      break;
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> mei[i][0] >> mei[i][1] >> mei[i][2] >> mei[i][3];
      mei[i][0]--;
      mei[i][1]--;
      mei[i][2]--;
    }
    while (1) {
      for (int f = 0; f < a + b + c; f++) {
        karibuhin[f] = buhin[f];
      }
      if (fl == 0)
        break;
      fl = 0;
      for (int i = 0; i < N; i++) {
        if (mei[i][3] == 1) {
          buhin[mei[i][0]] = 1;
          buhin[mei[i][1]] = 1;
          buhin[mei[i][2]] = 1;
        } else if (mei[i][3] == 0) {
          if (buhin[mei[i][0]] == 1 && buhin[mei[i][1]] == 1) {
            buhin[mei[i][2]] = 0;
          }
          if (buhin[mei[i][1]] == 1 && buhin[mei[i][2]] == 1) {
            buhin[mei[i][0]] = 0;
          }
          if (buhin[mei[i][2]] == 1 && buhin[mei[i][0]] == 1) {
            buhin[mei[i][1]] = 0;
          }
        }
        for (int f = 0; f < a + b + c; f++) {
          if (karibuhin[f] != buhin[f]) {
            fl++;
          }
        }
      }
    }
    for (int lk = 0; lk < a + b + c; lk++) {
      cout << buhin[lk] << endl;
    }
  }
}