Cod sursa(job #2482202)

Utilizator miruna1224Floroiu Miruna miruna1224 Data 27 octombrie 2019 21:17:28
Problema Dusman Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <iostream>
#include <cstdio>
#include <stdlib.h>

using namespace std;

//ifstream in ("dusman.in");
//ofstream out ("dusman.out");

FILE *of2 ;

int st[1001], a[1001][1001], ut[1001], k, n, m, k1;


void afisare()
{
	for(int i = 1; i <= n; i++)
		//out << st[i] << " ";
		fprintf ( of2, "%d ", st[i]);
}

void bkt(int i)
{
	for(int kk = 1; kk <= n; kk++)
	{
		if( !a[st[i - 1]][kk] && !ut[kk])
		{
			st[i] = kk;
			ut[kk] = 1;
			if(i == n)
			{
				k1++;
				if(k1 == kk)
					afisare();
				ut[kk] = 0;
			}
			else{
				bkt(i + 1);
				ut[kk] = 0;
			}
		}
	}
}


int main()
{
	//ios::sync_with_stdio(false);
	int v1,v2;
	FILE *of = fopen ( "dusman.in", "r");
	of2 = fopen ( "dusman.out", "w");

	if ( fscanf( of,  "%d%d%d", &n ,&k, &m) < 0 )
		return 0;

	for(int i = 1; i <= m ; i++)
	{
		fscanf ( of, "%d %d", &v1, &v2);
		a[v1][v2] = 1;
		a[v2][v1] = 1;
	}

	bkt(1);

	fclose(of);
	fclose(of2);
	//in.close();
	//out.close();

	return 0;
}