Cod sursa(job #1401212)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 25 martie 2015 18:26:25
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include<fstream>

using namespace std;

ifstream fin( "dusman.in" );
ofstream fout( "dusman.out" );

const int nmax = 1000;
int k, n;
bool d[ nmax + 1 ][ nmax + 1 ];
bool f[ nmax + 1 ];
int v[ nmax + 1 ];

void bck( int pos ) {
    if ( pos == n + 1 ) {
        -- k;
        if ( k == 0 ) {
            for( int i = 1; i <= n; ++ i ) fout << v[ i ] << " ";
            fout << "\n";
        }
        return ;
    }
    for( v[ pos ] = 1; v[ pos ] <= n && k > 0; ++ v[ pos ] ) {
        if ( f[ v[ pos ] ] == 0 && d[ v[ pos - 1 ] ][ v[ pos ] ] == 0 ) {
            f[ v[ pos ] ] = 1;
            bck( pos + 1 );
            f[ v[ pos ] ] = 0;
        }
    }
}
int main() {
    int q;
    fin >> n >> k >> q;
    while ( q -- ) {
        int x, y;
        fin >> x >> y; d[ x ][ y ] = d[ y ][ x ] = 1;
    }
    bck( 1 );
    fin.close();
    fout.close();
    return 0;
}