Cod sursa(job #2433229)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 26 iunie 2019 13:50:44
Problema Balanta Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <fstream>
using namespace std;
ifstream in("balanta.in");
ofstream out("balanta.out");

const int nmax = 1028;
int n, m, k, greu[nmax], usor[nmax], ok[nmax],v[2][nmax], neok, nrgreu, nrusor;

int main()
{
    in>>n>>m;
    for(int shp = 0; shp<m; shp++)
    {
        in>>k;

        for(int i = 1; i<=k; i++)
        {
            in>>v[0][i];
        }
        for(int i = 1; i<=k; i++)
        {
            in>>v[1][i];
        }

        int balanta;
        in>>balanta;

        if(balanta==0)
        {
            for(int i = 1; i<=k; i++)
            {
                ok[v[1][i]] = 1;
                ok[v[0][i]] = 1;
            }

            continue;
        }

        balanta--;
        for(int i = 1; i<=k; i++)
            greu[v[balanta][i]] = 1;
        for(int i = 1; i<=k; i++)
            usor[v[1 - balanta][i]] = 1;
    }

    for(int i = 1; i<=n; i++)
    {
        if(greu[i]==1 && usor[i]==1)
            ok[i] = 1;
    }

    for(int i = 1; i<=n; i++)
    {
        if(greu[i]==1 && ok[i]==0)
            nrgreu++;
        if(usor[i]==1 && ok[i]==0)
            nrusor++;
    }

    if(nrgreu==1 && nrusor!=1)
    {
        for(int i = 1; i<=n; i++)
        {
            if(greu[i]==1 && ok[i]==0)
                out<<i<<'\n';
        }
        return 0;
    }

    if(nrgreu!=1 && nrusor==1)
    {
        for(int i = 1; i<=n; i++)
        {
            if(usor[i]==1 && ok[i]==0)
                out<<i<<'\n';
        }

        return 0;
    }

    out<<neok<<"\n";

    return 0;
}