Cod sursa(job #616866)

Utilizator laurionLaurentiu Ion laurion Data 13 octombrie 2011 16:20:18
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<cstdio>
#include<algorithm>
#include<cstring>
int n,k,m,st[1001],nr;
bool a[1001][1001],u[1001];
void back_it()
{
    int p,dummy;

    p=1;
    st[1]=0;

    while(p)
    {
        dummy=0;
        while(!dummy && st[p]<n)
        {
            st[p]++;
            if(!u[st[p]]&&!a[st[p]][st[p-1]])
                u[st[p]]=1,dummy=1;
        }
        if(dummy)
            if(p==n)
            {
                nr++;
                if(nr==k)
                    break;
                u[st[p]]=0;
            }
            else
                st[++p]=0;
        else
            u[st[--p]]=0;
    }
}
int main()
{

    int x,y;
    freopen("dusman.in","r",stdin);
    freopen("dusman.out","w",stdout);
    scanf("%d %d %d",&n,&k,&m);
    memset(a,0,sizeof(a));
    for(int i=1;i<=m;++i)
    {
        scanf("%d %d", &x,&y);
        a[x][y]=a[y][x]=1;
    }

    back_it();

//    afis();
    for(int i=1;i<=n;++i)
        printf("%d ",st[i]);

    return 0;
}