Pagini recente » Cod sursa (job #1018548) | Cod sursa (job #1477331) | Cod sursa (job #2686650) | Cod sursa (job #1137733) | Cod sursa (job #1686670)
#include <iostream>
#include <fstream>
#include <map>
#define nmax 1005
using namespace std;
int n, m, k, sol[nmax], nr = 0, x, y;
map <int, map<int, bool> > enemy;
bool used [nmax], gasit_solutie = 0;
ifstream f("dusman.in");
ofstream g("dusman.out");
void ins(int nod, int poz)
{
if (gasit_solutie) return;
sol[poz] = nod;
used[nod] = 1;
if (poz == n)
{
++nr;
if (nr == k)
{
for(int i=1; i<=n; ++i)
g << sol[i] << " ";
gasit_solutie = 1;
}
used[nod] = 0;
return;
}
for(int i=1; i<=n; ++i)
if (!used[i] & !enemy[nod][i])
{
ins(i, poz+1);
}
used[nod] = 0;
}
inline void back_track()
{
for(int i=1; i<=n; ++i)
{
if (gasit_solutie) return;
ins(i, 1);
}
}
int main()
{
f >> n >> k >> m;
for(int i=1; i<=m; ++i)
{
f >> x >> y;
enemy[x][y] = 1;
enemy[y][x] = 1;
}
back_track();
f.close();
g.close();
return 0;
}