Cod sursa(job #2818168)

Utilizator AACthAirinei Andrei Cristian AACth Data 15 decembrie 2021 14:36:20
Problema Dusman Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("dusman.in");
ofstream g("dusman.out");
#define cin f
#define cout g
// #define int long long
const int Max = 1e3 + 1;
void nos()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int n,k,m;
int d[Max][Max];
void read()
{
	f>>n>>k>>m;
	int i;
	for(i=1;i<=m;i++)
	{
		int a,b;
		f>>a>>b;
		d[a][b] = d[b][a] = 1;
	}
}
vector < int > perm;
bool viz[Max];
void bkt(int individ)
{	
	//cout<<individ<<' ';
	if(individ == n + 1)
	{
		k--;
		if(k == 0)
		{
			for(auto it : perm)
				cout<<it<<' ';
			exit(0);
		}
		return;
	}
	int nxt;
	for(nxt = 1;nxt <= n;nxt++)
		if(!viz[nxt] and ( perm.empty() or !d[perm.back()][nxt]))
		{
			//asta e urmatoru
			perm.push_back(nxt);
			viz[nxt] = true;
			bkt(individ + 1);
			viz[nxt] = false;
			perm.pop_back();
		}
}
void solve()
{
    bkt(1);
}
void restart()
{

}
int32_t main()
{
    nos();
   
        read();
        solve();
        restart();
    
    return 0;
}