Cod sursa(job #938011)

Utilizator raulmuresanRaul Muresan raulmuresan Data 11 aprilie 2013 16:29:54
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include<cstdio>
#include<bitset>
#define N 1001
using namespace std;

int i,j,n,k,m,rez[N],ok,x,y;
bitset <N> a[N];
bitset <N> fol;

void back(int i)
{
    if(i>n)
    {
        --k;
        if(!k)
        {
            for(int j=1;j<=n;++j) printf("%d ",rez[j]);
            printf("\n");
            ok=1;
        }
        return;
    }

    for(int j=1;j<=n&& ok==0;++j)
        if(fol[j] == 0 && a[rez[i-1]][j]==0)
        {
            rez[i]=j;
            fol[j]=1;
            back(i+1);
            fol[j]=0;
        }
}


int main()
{
    freopen ("dusman.in","r",stdin);
    freopen ("dusman.out","w",stdout);

    scanf("%d %d %d",&n,&k,&m);
    //printf("%d\n",k);
    for(i=1;i<=m;i++)
    {
        scanf("%d %d",&x,&y);
        //printf("%d %d\n",x,y);
        a[x][y]=a[y][x]=1;
    }
    i=1;
    ok=0;
    back(1);
}