Pagini recente » Cod sursa (job #2217002) | Cod sursa (job #2480446)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("dusman.in");
ofstream fout("dusman.out");
int N, K, M, ct;
int sol[1005];
bool a[1005][1005];
bool viz[1005],ok;
void Afisare()
{int i;
for(i=1;i<=N;i++)
fout<<sol[i]<<" ";
}
void Back(int top) {
int i;
if (top == N + 1) {
ct++;
if (ct == K) {Afisare();ok=1;}
}
else
for (i=1;i<=N;i++)
if(viz[i]==0&&a[sol[top-1]][i]==0)
{sol[top]=i;
viz[i]=true;
if(ok==0)
Back(top+1);
viz[i]=false;
}
}
int main() {
int i, x, y;
fin >> N >> K >> M;
for (i = 1; i <= M; i++) {
fin >> x >> y;
a[x][y] = true;
a[y][x] = true;
}
Back(1);
}