Cod sursa(job #267038)

Utilizator ConsstantinTabacu Raul Consstantin Data 26 februarie 2009 17:37:08
Problema Party Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.74 kb
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>

int ex[3][10011],i,j,k,l,n,nr,m,a,b,c,viz[111];

int exp(){
int i;
for(i=1;i<=n;i++)
        if(ex[2][i]==0)
                {if(!(viz[ex[0][i]]||viz[ex[1][i]]))
                   {l=rand()%2;
                   if(!viz[ex[l][i]]){nr++;viz[ex[l][i]]=1;return 0;}
                   else
                        {nr--;viz[ex[l][i]]=0;return 0;

                        }
                        }
               }
     else
     if(ex[2][i]==1)
        {if(viz[ex[0][i]]<viz[ex[1][i]])
                {l=rand()%2;
                if(!viz[ex[l][i]]){nr++;viz[ex[l][i]]=1;return 0;}
                   else
                        {nr--;viz[ex[l][i]]=0;return 0;

                        }
                }


        }
    else
    if(ex[2][i]==2)
        {if(viz[ex[0][i]]>viz[ex[1][i]])
        l=rand()%2;
        if(!viz[ex[l][i]]){nr++;viz[ex[l][i]]=1;return 0;}
                   else
                        {nr--;viz[ex[l][i]]=0;return 0;

                        }}
   else
   if(ex[2][i]==3)
        {if(viz[ex[0][i]]&&viz[ex[1][i]])
                {l=rand()%2;
                if(!viz[ex[l][i]]){nr++;viz[ex[l][i]]=1;return 0;}
                   else
                        {nr--;viz[ex[l][i]]=0;return 0;

                        }}
         }
return 1;
}
int main(){

FILE *f=fopen("party.in","r");
fscanf(f,"%d %d",&n,&m);

memset(viz,1,sizeof(viz));

for(i=1;i<=m;i++)
        fscanf(f,"%d %d %d ",&ex[0][i],&ex[1][i],&ex[2][i]);
nr=n;
srand(time(0));
k=exp();

while(!k)k=exp();
FILE *g=fopen("party.out","w");
fprintf(g,"%d\n",nr);
for(i=1;i<=n;i++)
        if(viz[i])fprintf(g,"%d\n",i);
fclose(g);
return 0;}