Pagini recente » Istoria paginii runda/runda_runda_runda | Cod sursa (job #2900509) | Rating Salam Alecu (NoNAME-King) | Cod sursa (job #1902119) | Cod sursa (job #667901)
Cod sursa(job #667901)
#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 && K; ++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;
}