Mai intai trebuie sa te autentifici.

Cod sursa(job #2106002)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 14 ianuarie 2018 19:09:56
Problema Balanta Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.24 kb
#include<fstream>
using namespace std;
ifstream in ("balanta.in");
ofstream out ("balanta.out");
int x,n,m,tip[1030],a[1030],b[1030],hz[1030],rez,sol,alfa;
int main (void) {
    in >> n >> m;
    for (int j = 1; j <= m; j ++) {
        in >> x;
        for (int i = 1; i <= x; i ++) {
            in >> a[i];
        }
        for (int i = 1; i <= x; i ++) {
            in >> b[i];
        }
        for (int i = 1; i <= n; i ++) {
            hz[i] = 0;
        }
        in >> rez;
        if (rez == 0) {
            for (int i = 1; i <= x; i ++) {
                tip[a[i]] = -1;
                tip[b[i]] = -1;
            }
        }
        if (rez == 1) {
            for (int i = 1; i <= x; i ++) {
                if (tip[a[i]] == 0) {
                    tip[a[i]] = 1;
                }
                if (tip[a[i]] == 2) {
                    tip[a[i]] = -1;
                }
                if (tip[b[i]] == 0) {
                    tip[b[i]] = 2;
                }
                if (tip[b[i]] == 1) {
                    tip[b[i]] = -1;
                }
                hz[a[i]] = 1;
                hz[b[i]] = 1;
            }
            for (int i = 1; i <= n; i ++) {
                if (hz[i] == 0) {
                    tip[i] = -1;
                }
            }
        }
        if (rez == 2) {
            for (int i = 1; i <= x; i ++) {
                if (tip[a[i]] == 0) {
                    tip[a[i]] == 2;
                }
                if (tip[a[i]] == 1) {
                    tip[a[i]] = -1;
                }
                if (tip[b[i]] == 0) {
                    tip[b[i]] = 1;
                }
                if (tip[b[i]] == 2) {
                    tip[b[i]] = -1;
                }
                hz[a[i]] = 1;
                hz[b[i]] = 1;
            }
            for (int i = 1; i <= n; i ++) {
                if (hz[i] == 0) {
                    tip[i] = -1;
                }
            }
        }

    }
    for (int i = 1; i <= n; i ++) {
        if (tip[i] != -1 && tip[i] != 0) {
            sol ++;
            alfa = i;
        }
    }
    if (sol == 1) {
        out << alfa;
    }
    else {
        out << 0;
    }

    return 0;
}