Cod sursa(job #27998)

Utilizator ionescu_bogdanIonescu Bogdan-Gabriel ionescu_bogdan Data 7 martie 2007 13:20:26
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define nmax 1025

int n,m,k,i,j,r,x,nh,nl;
short a[nmax],b[nmax],l[nmax],h[nmax];

int main()
{
    freopen("balanta.in","r",stdin);
    freopen("balanta.out","w",stdout);

    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
        l[i]=h[i]=1;
    for (j=0;j<m;j++)
    {
        scanf("%d",&k);
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for (i=0;i<k;i++)
            scanf("%d",&x),a[x]=1;
        for (i=0;i<k;i++)
            scanf("%d",&x),b[x]=1;
        scanf("%d",&r);
        if (r==0)
        {
            for (i=1;i<=n;i++)
                if (a[i]||b[i])
                    l[i]=h[i]=0;
        }
        else
            if (r==1)
            {
                for (i=1;i<=n;i++)
                    if (h[i]&&(!a[i]))
                        h[i]=0;
                for (i=1;i<=n;i++)
                    if (l[i]&&(!b[i]))
                        l[i]=0;
            }
            else
            {
                for (i=1;i<=n;i++)
                    if (h[i]&&(!b[i]))
                        h[i]=0;
                for (i=1;i<=n;i++)
                    if (l[i]&&(!a[i]))
                        l[i]=0;
            }
    }
    for (i=1;i<=n;i++)
        nh+=h[i],nl+=l[i];
    if (nh+nl!=1)
        printf("0\n");
    else
    {
        for (i=1;i<=n;i++)
            if (h[i]||l[i])
                printf("%d\n",i);
    }

    return 0;
}