Cod sursa(job #1573579)

Utilizator cameleonGeorgescu Dan cameleon Data 19 ianuarie 2016 19:52:42
Problema Balanta Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <cstdio>

using namespace std;
#define NMAX 1030
int a[NMAX][NMAX], n, m, k ,v[NMAX],i,j,x,fals,usor,greu,nr;
bool bun;
int main()
{
    freopen("balanta.in","r",stdin);
    freopen("balanta.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(i = 1; i <= m; i++)
    {
        scanf("%d",&k);
        for(j = 1; j <= k;j++){
            scanf("%d",&x);
            a[i][x] = 1;
        }
        for(j = 1; j <= k;j++){
            scanf("%d",&x);
            a[i][x] = 2;
        }
        scanf("%d",&a[i][0]);
    }

    for(i = 1; i <= n; i++)
    {
        bun =true;
        for(j = 1; j <= m; j++)
            {if(a[j][i] == 0)
                if(a[j][0] == 0)
                    v[j] = 0;
                else
                    { bun = false;
                      break;
                    }
            else
                if(a[j][i] == a[j][0])
                    v[j] = 2;//greu
                else
                    v[j] = 1;//usor
            }
            usor=greu=0;
            for(j = 1; j <= m; j++)
                {
                    switch(v[j])
                    {
                        case 1: usor++;break;
                        case 2: greu++; break;
                    }
                    v[j] = 0;
                }
            if(usor>0 && greu>0)
                bun=false;
            if(bun){
                nr++;
                fals = i;
            }

    }
    if(nr == 1) printf("%d", fals);
    else printf("0");
        return 0;
}