Cod sursa(job #1184258)

Utilizator EpictetStamatin Cristian Epictet Data 11 mai 2014 21:43:25
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
using namespace std;
ifstream fin("balanta.in");
ofstream fout("balanta.out");
int n,m,k,rez,nr,nr1,nr2,sol1,sol2,G[1050],U[1050],V1[1050],V2[1050];
int main()
{
    fin >> n >> m;
    for(int i=1; i<=n; i++) G[i]=U[i] = 1;
    for(int i=1; i<=m; i++)
    {
        fin >> k;
        for(int j=1; j<=n; j++) V1[j] = V2[j] = 0;
        for(int j=1; j<=k; j++) fin >> nr, V1[nr] = 1;
        for(int j=1; j<=k; j++) fin >> nr, V2[nr] = 1;
        fin >> rez;
 
        if(!rez)
        {
            for(int j=1; j<=n; j++)
            {
                if(V1[j]) G[j]=0, U[j]=0;
                if(V2[j]) G[j]=0, U[j]=0;
            }
        }
        else if(rez == 1)
        {
            for(int j=1; j<=n; j++) G[j] *= V1[j], U[j] *= V2[j];
        }
        else
        {
            for(int j=1; j<=n; j++) U[j] *= V1[j], G[j] *= V2[j];
        }
    }
 
    for(int i=1; i<=n; i++)
    {
        if(G[i] == 1) nr1++, sol1 = i;
        if(U[i] == 1) nr2++, sol2 = i;
    }
 
    if(nr1 == 1 && nr2 == 0) fout << sol1 << '\n';
    else if(nr2 == 1 && nr1 == 0) fout << sol2 << '\n';
    else fout << "0\n";
 
    fout.close();
    return 0;
}