Cod sursa(job #158175)

Utilizator jeanFMI - Petcu Ion Cristian jean Data 13 martie 2008 14:53:51
Problema Dusman Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream.h>
char a[1000][1000];
int q,cont,n,k,m,i,z,y,t,x[1000],c,v[1000];
int main()
{
ifstream f("dusman.in");f>>n>>k>>m;
ofstream g("dusman.out");
for(i=0;i<m;i++) {f>>z>>y;a[z][y]=a[y][z]=1;}
q=t=1;

while(t>0&&q)
 if(x[t]<n)
  {
   x[t]++;
   cont=1;
   if(t>1) if(a[x[t-1]][x[t]]||v[x[t]]) cont=0;
   if(cont)
   {
    v[x[t]]=1;
    if(t==n)
     {
      c++;
     if (c==k) {for(i=1;i<=t;i++)
	 g<<x[i]<<' '; q=0;}
     v[x[t]]=0;

	 }


    else
     {
      t++;  x[t]=0;      }
   }
     }
 else {  t--;v[x[t]]=0;}
g.close();
f.close();
return 0;
}