Pagini recente » Cod sursa (job #2047781) | Cod sursa (job #2727199) | Cod sursa (job #2633824) | Cod sursa (job #2007903) | Cod sursa (job #1687511)
#include <fstream>
#define nmax 1005
using namespace std;
ifstream fin("dusman.in");
ofstream fout("dusman.out");
int n, k, m, numbering, v[nmax];
bool matrix[nmax][nmax], is[nmax], exit_function;
void write_out() {
for (int i = 1; i <= n; ++i)
fout << v[i] << " ";
}
void back_track(int position) {
for (int i = 1; i <= n; ++i) {
bool enter = false;
if (!matrix[v[position - 1]][i] and !matrix[i][v[position - 1]] and !is[i]) {
enter = true;
is[i] = true;
v[position] = i;
if (position == n) {
++numbering;
if (numbering == k) {
write_out();
}
}
else
back_track(position + 1);
}
if (exit_function)
return;
if (enter)
is[i] = false;
}
}
int main()
{
fin >> n >> k >> m;
for (int i = 1; i <= m; ++i) {
int a, b;
fin >> a >> b;
matrix[a][b] = matrix[b][a] = true;
}
back_track(1);
return 0;
}