Pagini recente » Cod sursa (job #89308) | Cod sursa (job #2264793) | Cod sursa (job #1913454) | Cod sursa (job #2553292) | Cod sursa (job #237492)
Cod sursa(job #237492)
#include <stdio.h>
int a[1030],b[1030],u[1030],v[1030];
int n,m,k,t;
void scoate (int x[1030],int y[1030])
{
int z[1030],w[1030],i;
for (i=0; i<=1024; ++i)
z[i]=w[i]=0;
z[0]=x[0];
for (i=1; i<=x[0]; ++i)
z[x[i]]=1;
w[0]=y[0];
for (i=1; i<=y[0]; ++i)
w[y[i]]=1;
for (i=0; i<=1024; ++i)
x[i]=0;
for (i=1; i<=1024; ++i)
if (z[i] && !w[i])
x[++x[0]]=i;
}
void inter (int x[1030],int y[1030])
{
int z[1030],w[1030],i;
for (i=0; i<=1024; ++i)
z[i]=w[i]=0;
z[0]=x[0];
for (i=1; i<=x[0]; ++i)
z[x[i]]=1;
w[0]=y[0];
for (i=1; i<=y[0]; ++i)
w[y[i]]=1;
for (i=0; i<=1024; ++i)
x[i]=0;
for (i=1; i<=1024; ++i)
if (z[i] && w[i])
x[++x[0]]=i;
}
int main ()
{
freopen ("balanta.in","r",stdin);
freopen ("balanta.out","w",stdout);
int i,j;
scanf ("%d%d",&n,&m);
a[0]=b[0]=n;
for (i=1; i<=n; ++i)
a[i]=b[i]=i;
for (i=1; i<=m; ++i)
{
scanf ("%d",&k);
u[0]=v[0]=k;
for (j=1; j<=k; ++j)
scanf ("%d",&u[j]);
for (j=1; j<=k; ++j)
scanf ("%d",&v[j]);
scanf ("%d",&t);
if (t==0)
{
scoate (a,u);
scoate (a,v);
scoate (b,u);
scoate (b,v);
}
else if (t==1)
{
inter (a,u);
inter (b,v);
}
else if (t==2)
{
inter (a,v);
inter (b,u);
}
}
if (a[0]==1 && !b[0])
printf ("%d",a[1]);
else if (!a[0] && b[0]==1)
printf ("%d",b[1]);
else
printf ("0");
return 0;
}