Cod sursa(job #1343083)

Utilizator razboi4Manole Iulian razboi4 Data 14 februarie 2015 21:06:45
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include<stdio.h>
using namespace std;
int N,K,M,dajman[1005][1005],asezare,st[1005];bool ok,sw[1005];
void read()
{
    freopen("dusman.in","r",stdin);
    scanf("%d%d%d",&N,&K,&M);
    for( ; M ; --M ){
        int a,b;
        scanf("%d%d",&a,&b);
        dajman[a][b]=dajman[b][a]=1;
    }
}
void magic(int pas)
{
    if(pas==N){
        asezare++;
        if(asezare==K){
            ok=1;
            for(int i=1;i<=N;++i)
                printf("%d ",st[i]);
        }
        return ;
    }
    for(int i=1;i<=N;++i){
        if(ok) return ;
        if(!dajman[st[pas]][i] && !sw[i]){
            sw[i]=1;
            st[pas+1]=i;
            magic(pas+1);
            sw[i]=0;
        }
    }

}
int main()
{
    freopen("dusman.out","w",stdout);
    read();
    magic(0);
    return 0;
}