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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#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 < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, string> pis;

const int INF = 10000000;

int main() {
  int a, b, c, r, n;
  while (cin >> a >> b >> c) {
    if (a == 0 && b == 0 && c == 0)
      break;
    vii v;
    cin >> n;
    int x, y, z;
    for (int i = 0; i < n; i++) {
      cin >> x >> y >> z >> r;
      x--;
      y--;
      z--;
      r = (r + 1) % 2;
      vi u;
      u.pb(r);
      u.pb(x);
      u.pb(y);
      u.pb(z);
      v.pb(u);
    }

    sort(all(v));

    vi u(a + b + c, 2);
    for (int i = 0; i < n; i++) {
      if (v[i][0] == 0) {
        for (int j = 1; j < 4; j++) {
          u[v[i][j]] = 1;
          // cout<<" "<<v[i][j];
        }
        // cout<<endl;
      } else {
        if (u[v[i][1]] == 2 && u[v[i][2]] == 1 && u[v[i][3]] == 1)
          u[v[i][1]] = 0;
        else if (u[v[i][1]] == 1 && u[v[i][2]] == 2 && u[v[i][3]] == 1)
          u[v[i][2]] = 0;
        else if (u[v[i][1]] == 1 && u[v[i][2]] == 1 && u[v[i][3]] == 2)
          u[v[i][3]] = 0;
      }
    }

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

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#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 < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, string> pis;

const int INF = 10000000;

int main() {
  int a, b, c, r, n;
  while (cin >> a >> b >> c) {
    if (a == 0 && b == 0 && c == 0)
      break;
    vii v;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> r;
      a--;
      b--;
      c--;
      r = (r + 1) % 2;
      vi u;
      u.pb(r);
      u.pb(a);
      u.pb(b);
      u.pb(c);
      v.pb(u);
    }

    sort(all(v));

    vi va(a, 2), vb(b, 2), vc(c, 2);

    for (int i = 0; i < n; i++) {
      if (v[i][0] == 0) {
        va[v[i][1]] = 1;
        vb[v[i][2]] = 1;
        vc[v[i][3]] = 1;
      } else {
        if (va[v[i][1]] == 2 && vb[v[i][2]] == 1 && vc[v[i][3]] == 1)
          va[v[i][1]] = 0;
        else if (va[v[i][1]] == 1 && vb[v[i][2]] == 2 && vc[v[i][3]] == 1)
          vb[v[i][2]] = 0;
        else if (va[v[i][1]] == 1 && vb[v[i][2]] == 1 && vc[v[i][3]] == 2)
          vc[v[i][3]] = 0;
      }
    }
    for (int i = 0; i < a; i++)
      cout << va[i] << endl;
    for (int i = 0; i < b; i++)
      cout << vb[i] << endl;
    for (int i = 0; i < c; i++)
      cout << vc[i] << endl;
  }
}