Cod sursa(job #25089)

Utilizator mariusdrgdragus marius mariusdrg Data 4 martie 2007 10:32:26
Problema Balanta Scor 100
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasa a 10-a Marime 3.17 kb
#include<stdio.h>

const int maxn = 1100;


int n;
int i;
int m;
int j;
int r;
int aux;
int count;
int vect1[maxn];
int vect2[maxn];
int a[maxn];
int b[maxn];
int el;


int main()
{
        freopen("balanta.in","r",stdin);
        freopen("balanta.out","w",stdout);
        scanf("%d %d",&n,&m);
        for(i = 1; i <= n; ++i)
        {
                vect1[i] = 1;
                vect2[i] = 1;
        }
        for(i = 1; i <= m; ++i)
        {
                scanf("%d",&el);
                for(j = 1; j <= el; ++j)
                {
                        scanf("%d",&a[j]);
                }
                for(j = 1; j <= el; ++j)
                {
                        scanf("%d",&b[j]);
                }
                scanf("%d",&r);
                if (r == 0)
                {
                        for(j = 1; j <= el; ++j)
                        {
                                vect1[a[j]] = 0;
                                vect2[a[j]] = 0;
                                vect1[b[j]] = 0;
                                vect2[b[j]] = 0;
                        }
                }
                if (r == 1)
                {
                        for(j = 1;j <= el; ++j)
                        {
                                if (vect1[a[j]] == 1)vect1[a[j]] = 2;
                                if (vect2[b[j]] == 1)vect2[b[j]] = 2;
                                vect2[a[j]] = 0;
                                vect1[b[j]] = 0;
                        }
                        for(j = 1;j <= n; ++j)
                        {
                                if (vect1[j] == 2) vect1[j] = 1;
                                        else vect1[j] = 0;
                                if (vect2[j] == 2) vect2[j] = 1;
                                        else vect2[j] = 0;

                        }
                        
                }
                if (r == 2)
                {
                        for(j = 1;j <= el;++j)
                        {
                                if (vect2[a[j]] == 1)vect2[a[j]] = 2;
                                if (vect1[b[j]] == 1)vect1[b[j]] = 2;
                    
                                vect1[a[j]] = 0;
                                vect2[b[j]] = 0;
                        }
                        for(j = 1;j <= n; ++j)
                        {
                                if (vect1[j] == 2) vect1[j] = 1;
                                        else vect1[j] = 0;
                                if (vect2[j] == 2) vect2[j] = 1;
                                        else vect2[j] = 0;

                        }
      
                }
                
        }
        for(i = 1; i <= n; ++i)
        {
                if (vect1[i] != 0)
                {
                        aux = i;
                        count++;
                }
                if (vect2[i] != 0)
                {
                        aux = i;
                        count++;
                }
        }
        if (count == 1) printf("%d\n",aux);
                else printf("0\n");
        return 0;
        

}