Cod sursa(job #237148)

Utilizator crawlerPuni Andrei Paul crawler Data 29 decembrie 2008 01:34:07
Problema Party Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <stdio.h>

#define Nmax 128
#define Mmax 1024

int val[Nmax], a[Mmax][2], n,m;

int main()
{
    freopen("party.in","r",stdin);
    freopen("party.out","w",stdout);
    
    scanf("%d%d", &n,&m);
    
    for (int i=1;i<=n;++i) val[i] = 1;
    
    int x,y,op;
    
    for (int i=1;i<=m;++i)
    {
        scanf("%d%d%d", &x,&y,&op);
        
        if (op == 0) { a[i][0] = x; a[i][1] = y; } else
        if (op == 1) { a[i][0] = x; a[i][1] = -y; } else
        if (op == 2) { a[i][0] = -x; a[i][1] = y; } else
        if (op == 3) { a[i][0] = -x; a[i][1] = -y; }          
    }
    
    int notOK=1;

    while (notOK)
    {
        notOK = 0;  
        for (int i=1;i<=m;++i) 
        {
            if (a[i][0] > 0) x = val[a[i][0]]; else x = !val[-a[i][0]];
            if (a[i][1] > 0) y = val[a[i][1]]; else y = !val[-a[i][1]];
            op = (op+1)%1235;
            if (y == 0 && x == 0)
            {
               if (op % 2 == 0)
               {
                   x = a[i][0];
                   if (x < 0) x = -x;
                   val[x] ^= 1;                                       
               }      
               else
               {
                   y = a[i][1];
                   if (y < 0) y = -y;
                   val[y] ^= 1;                  
               }
               notOK = 1;
            }
        }        
    }
    
    int cnt=0;
    for (int i=1;i<=n;++i) cnt += val[i];
    
    printf("%d\n", cnt);
    
    for (int i=1;i<=n;++i) if (val[i]==1) printf("%d\n", i);   

    return 0;    
}