Cod sursa(job #1117860)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 23 februarie 2014 20:42:12
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

ifstream f("dusman.in");
ofstream g("dusman.out");

int v[1005];

bool ok[1005][1005], ap[1005];

int r,k,m,o,n,i,x,y;

void back(int i) {
    if(i==n+1) {
        r++;
        if(r==k) {
            for (int j=1;j<=n;j++)
                g<<v[j]<<" ";
            o=0;
        }
        return ;
    }
    for(int j=1;j<=n && o;j++) {
        if(ap[j]==0 && ok[v[i-1]][j]==0) {
            v[i]=j;
            ap[j]=1;
            back(i+1);
            ap[j]=0;
        }
    }
}

int main() {
    f>>n>>k>>m;
    for(i=1;i<=m;i++) {
        f>>x>>y;
        ok[x][y]=1;
        ok[y][x]=1;
    }
    o=1;
    back(1);
    return 0;
}