Pagini recente » Cod sursa (job #938435) | Cod sursa (job #3177761) | Cod sursa (job #1308760) | Cod sursa (job #566107) | Cod sursa (job #1401212)
#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;
}