Cod sursa(job #157547)

Utilizator GotenAmza Catalin Goten Data 13 martie 2008 09:15:34
Problema Dusman Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream.h>
int a[1000][3],cont,n,k,m,i,z,y,t,x[1000],c;
int main()
{
ifstream f("dusman.in");f>>n>>k>>m;
ofstream g("dusman.out");
for(i=0;i<m;i++){f>>z>>y;if(!a[z][0])
			  {
			   a[z][0]=y;
			   if(!a[y][0])a[y][0]=z;
			   else if(!a[y][1])a[y][1]=z;
				else a[y][2]=z;
			   }
			 else if(!a[z][1])
			       {
				a[z][1]=y;
				if(!a[y][0])a[y][0]=z;
				else if(!a[y][1])a[y][1]=z;
				     else a[y][2]=z;
				}
			      else
			       {
				a[z][2]=y;
				if(!a[y][0])a[y][0]=z;
				else if(!a[y][1])a[y][1]=z;
				     else a[y][2]=z;
				}
		 }
t=1;
while(t>0)
 if(x[t]<n)
  {
   x[t]++;
   cont=1;
   for(i=1;i<t;i++)if(x[i]==x[t]) cont=0;
   if(a[x[t-1]][0]==x[t]||a[x[t-1]][1]==x[t]||a[x[t-1]][2]==x[t])cont=0;
   if(cont)
    if(t==n)
     {
      c++;
      if(c==k)for(i=1;i<=t;i++)g<<x[i]<<' ';
      }
    else
     {
      t++;
      x[t]=0;
      }
   }
 else t--;
g.close();
f.close();
return 0;
}