Pagini recente » Cod sursa (job #2205385) | Cod sursa (job #1160722) | Cod sursa (job #1116303) | Cod sursa (job #1949439) | Cod sursa (job #667899)
Cod sursa(job #667899)
#include <fstream>
#define nmax 1005
using namespace std;
int st[nmax], n, m, K, a[nmax][nmax], viz[nmax];
ifstream f("dusman.in");
ofstream g("dusman.out");
void citeste(){
f>>n>>K>>m;
for(int i=1; i<=m; ++i){
int x, y;
f>>x>>y;
a[x][y] = 1;
a[y][x] = 1;
}
}
int valid(int x){
if (viz[st[x]] == 0 && a[st[x-1]][st[x]]==0) return 1;
return 0;
}
void scrie(){
for(int i=1; i<=n; ++i) g<<st[i]<<" ";
}
void back(int poz){
for(int i=1; i<=n; ++i){
st[poz] = i;
if (valid(poz)){
if (poz==n){ --K; if (K==0){ scrie(); return;}}
else {
viz[i] = 1;
back(poz+1);
viz[i] = 0;}
}
}
}
int main(){
citeste();
back(1);
f.close();
g.close();
return 0;
}