Cod sursa(job #623677)

Utilizator bora_marianBora marian bora_marian Data 20 octombrie 2011 16:06:43
Problema Dusman Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>
#include<vector>
using namespace std;
int a[1024][1024],n,m,K,pp,sol[1024];
vector<int>G[1024];
void back(int k);
int verif(int c,int lun);
int main()
{
	ifstream fin("dusman.in");
	ofstream fout("dusman.out");
	fin>>n>>K>>m;
	int i,aa,bb;
	for(i=1;i<=n;i++)
	{
		fin>>aa>>bb;
		a[aa][bb]=1;
		a[bb][aa]=1;
	}
	back(1);
	for(i=1;i<=n;i++)
		fout<<sol[i]<<" ";
	return 0;
}
void back(int k)
{
	int i;
	for(i=1;i<=n && K>0;i++)
		if(a[sol[k-1]][i]==0 && verif(i,k-1)==1)
		{
			sol[k]=i;
			if(k==n)
				K--;
			else
				back(k+1);
		}
}
int verif(int c,int lun)
{
	int i,pp=0;
	for(i=1;i<=lun && pp==0;i++)
		if(sol[i]==c)
			pp=1;
	if(pp==0)
		return 1;
	return 0;
}