Pagini recente » Cod sursa (job #585345) | Cod sursa (job #1584850) | Cod sursa (job #2361663) | Cod sursa (job #263364) | Cod sursa (job #1686645)
#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])
{
// cout << nod << "-->" << i << " poz " << poz << "\n";
ins(i, poz+1);
}
used[nod] = 0;
}
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;
}