Cod sursa(job #203809)

Utilizator alexeiIacob Radu alexei Data 19 august 2008 20:23:57
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.88 kb
#include<stdio.h>
#define nmax 1025

bool G[nmax],U[nmax];
int left[nmax],right[nmax];
bool l[nmax],r[nmax];

int main()
{
 freopen("balanta.in","r",stdin);
 freopen("balanta.out","w",stdout);
 
 int N,M;
 scanf("%d%d",&N,&M);
 
 int sf,a1,a2,ok;
 int i,j;
 
 for(i=1; i<=N; ++i)
 G[i]=U[i]=true;
 
 int A=N,B=N;

 for(i=1; i<=M; ++i){
    scanf("%d",&sf);
    
    for(j=1; j<=N; ++j)
    l[j]=r[j]=false;
    
    for(j=1; j<=sf; ++j){
    scanf("%d",&a1);
    l[ a1 ]=true;
    left[j]=a1;
    }
    
    for(j=1; j<=sf; ++j){
    scanf("%d",&a2);
    r[ a2 ]=true;
    right[j]=a2;
    }
    
    scanf("%d",&ok);
    
    if( !ok ){
        for(j=1; j<=sf; ++j){//taraneala
                 if( G[ left[j] ]==true )
                 --A,G[left[j]]=false;
                 if( G[ right[j] ]==true )
                 --A,G[right[j]]=false;
                 if( U[ left[j] ]==true )
                 --B,U[left[j]]=false;
                 if( U[ right[j] ]==true )
                 --B,U[right[j]]=false;
                 }
        
        }
    else
        if( ok==1 ){
            for(j=1; j<=N; ++j){
                     if( l[j]==false && G[j]==true )
                     G[j]=false,--A;
                     if( r[j]==false && U[j]==true )
                     U[j]=false,--B;
                     }
            
            }
    else
        if( ok==2 ){
            for(j=1; j<=N; ++j){
                     if( l[j]==false && U[j]==true )
                     U[j]=false,--B;
                     if( r[j]==false && G[j]==true )
                     G[j]=false,--A;
                     }
            }
 
 }
 
 if( (A==1 && B==0) || (A==0 && B==1) )
           for(i=1; i<=N; ++i)
           if( G[i]==true || U[i]==true ){
           printf("%d\n",i);return 0;
           }
 
    printf("%d\n",0);
    
    return 0;
}