Cod sursa(job #575361)

Utilizator borsoszalanBorsos Zalan borsoszalan Data 8 aprilie 2011 10:43:06
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<stdio.h>
#include<bitset>
#define N 1001
using namespace std;

int i,j,n,k,m,rez[N],ok;
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;++j)
		if(!fol[j]&&!a[rez[i-1]][j])
		{
			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);	
	for(i=1;i<=m;++i) 
	{
		int l=0,c=0;
		scanf("%d %d",&c,&l);		
		a[c][l]=1;
		a[l][c]=1;
	}
	back(1);
	return 0;
}