Cod sursa(job #1225121)

Utilizator tudorv96Tudor Varan tudorv96 Data 31 august 2014 23:40:32
Problema Balanta Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.87 kb
#include <fstream>
using namespace std;

ifstream fin ("balanta.in");
ofstream fout ("balanta.out");

const int N = 1030;

int n, m, v[N], w[N], now[N], sol, nr;

int main() {
    fin >> n >> m;
    for (int x, type, i = 1; i <= m; ++i) {
        fin >> x;
        for (int j = 0; j < (x << 1); ++j)
            fin >> w[j];
        fin >> type;
        if (!type)
            for (int j = 0; j < x; ++j)
                v[w[j]] = 3;
        else {
            if (type == 1) {
                for (int j = 0; j < x; ++j) {
                    if (!v[w[j]])
                        v[w[j]] = 1;
                    if (v[w[j]] == 2)
                        v[w[j]] = 3;
                    now[w[j]] = i;
                }
                for (int j = x; j < (x << 1); ++j) {
                    if (!v[w[j]])
                        v[w[j]] = 2;
                    if (v[w[j]] == 1)
                        v[w[j]] = 3;
                    now[w[j]] = i;
                }
            }
            if (type == 2) {
                for (int j = x; j < (x << 1); ++j) {
                    if (!v[w[j]])
                        v[w[j]] = 1;
                    if (v[w[j]] == 2)
                        v[w[j]] = 3;
                    now[w[j]] = i;
                }
                for (int j = 0; j < x; ++j) {
                    if (!v[w[j]])
                        v[w[j]] = 2;
                    if (v[w[j]] == 1)
                        v[w[j]] = 3;
                    now[w[j]] = i;
                }
            }
            for (int j = 1; j <= n; ++j)
                if (now[j] < i)
                    v[j] = 3;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (v[i] == 1 || v[i] == 2) {
            sol++;
            nr = i;
        }
    }
    if (sol != 1)
        fout << 0;
    else
        fout << nr;
}