Cod sursa(job #781421)

Utilizator MtkMarianHagrSnaf MtkMarian Data 24 august 2012 14:01:08
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<cstdio>
#include<iostream>
int main()
{
	freopen("balanta.in","r",stdin);
	freopen("balanta.out","w",stdout);
	int n,m,k,a[1024],b[1024],r,h[1024],l[1024],x;
	scanf("%d %d",&n,&m);	
	for (int j=1;j<=n;j++)
		{
		h[j]=l[j]=1;
		}
	for(int i=1;i<=m;++i)
	{
		scanf("%d",&k);
		for(int j=1;j<=n;j++)
		{
			a[j]=b[j]=0;
			
		}		
		for(int j=1;j<=k;++j)
		{
			scanf("%d",&x);
			a[x]=1;
		}
		for(int j=1;j<=k;++j)
		{
			scanf("%d",&x);
			b[x]=1;
		}
		
		scanf("%d",&r);

		if(r==0)
			for(int j=1;j<=n;++j)
				{
					if(a[j]==1)
						{
						h[j]=0;					
						l[j]=0;
						}
					else
						if(b[j]==1)
							{
							l[j]=0;
							h[j]=0;
							}
				}
		else
			if(r==1)			
				for(int j=1;j<=n;++j)							
				{
					if(l[j]!=1||b[j]!=1)l[j]=0;
					if(h[j]!=1||a[j]!=1)h[j]=0;
				}
			
			else 
				if(r==2)				
					for(int j=1;j<=n;++j)							
					{
						if(l[j]!=1||a[j]!=1)l[j]=0;
						if(h[j]!=1||b[j]!=1)h[j]=0;
					}	
					
	
	}
	
	
	int cont=0;
	int val=0;
	bool ok=true;
	for(int j=1;j<=n&&ok==true;++j)
	{
		if(h[j]==1)
		{
			
				cont++;
				val=j;
		}
		if(l[j]==1)
		{
			cont++;
			val=j;
		}
		if(cont>1)ok=false;
	}
	if(ok==false)printf("0");
	else printf("%d",val);

	return 0;
}