Pagini recente » Cod sursa (job #1473405) | Cod sursa (job #1430313) | Cod sursa (job #2937858) | Cod sursa (job #2000905) | Cod sursa (job #203809)
Cod sursa(job #203809)
#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;
}