Cod sursa(job #168245)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 30 martie 2008 22:07:49
Problema Dusman Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <stdio.h>
#include <algorithm>
#define N 1010
using namespace std;
int y[N][N],v[N];
int main(){
    int i,j,n,k,m,nr=0,a,b,sw;
    freopen("dusman.in","r",stdin);
    freopen("dusman.out","w",stdout);
    scanf("%d%d%d",&n,&k,&m);
    for (i=0;i<m;++i){
        scanf("%d%d",&a,&b);
        y[a][b]=1;
        y[b][a]=1;
    }
    for (i=1;i<=n;++i)
        v[i]=i;
    do{
        sw=1;
        for (i=2;i<=n && sw==1;++i)
            if (y[v[i-1]][v[i]]==1)
               sw=0;
        if (sw==1)
           ++nr;
        if (nr==k){
           for (i=1;i<=n;++i)
               printf("%d ",v[i]);
           return 0;
        }
    }while(next_permutation(v+1,v+n+1));
    return 0;
}