Cod sursa(job #162623)

Utilizator luana_0105Fagarasan Luana luana_0105 Data 20 martie 2008 13:24:12
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include<stdio.h>   
#include <stdlib.h>
#define nmax 1005   
  
unsigned char d[nmax][nmax];
int s[nmax], luat[nmax];   
int n,m,k,ct;   
  
void read()   
{   
     int i,n1,n2;   
     freopen("dusman.in","r",stdin);   
     freopen("dusman.out","w",stdout);   
     scanf("%d%d%d",&n, &k, &m);   
     for (i=1; i<=m; ++i)   
     {   
         scanf("%d%d", &n1, &n2);   
         d[n1][n2]=1;   
         d[n2][n1]=1;   
     }   
}   
  
  
void print()   
{   
     for(int i=1; i<=n; i++)   
        printf("%d ", s[i]);   
      printf("\n");   
      exit(0);
}   
       
       
  
void bec(int p)   
{   
     for(int i=1; i<=n; ++i)   
     {   
          if(d[i][s[p-1]]==0&&luat[i]==0)   
          {   
           s[p]=i;   
           luat[i]=1;   
           if(p==n)   
            {   
               ct++;   
               if(ct==k)   
               {   
                   print();   
                   return;   
               }   
            }   
            else   
                bec(p+1);   
            luat[i]=0;   
           }   
     }   
}   
  
int main()   
{   
    read();   
    bec(1);   
    return 0;   
}