Cod sursa(job #3302160)

Utilizator Martin_BohonyiMartin Bohonyi Martin_Bohonyi Data 4 iulie 2025 00:01:03
Problema Dusman Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include<fstream>

using namespace std;

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

int N , K , M , X[1001];
bool Dusman[1001][1001];
bool Asezat[1001];
bool Gasit;

void Sol(){
     Gasit=true;
     for(int i=1 ; i<=N ; i++){
         fout<<X[i]<<' ';
     }
     fout<<'\n';
 }

void Back(int k){
     if(Gasit)
          return;
     for(int Pers=1 ; Pers<=N ; Pers++){
         X[k]=Pers;
         if(!Asezat[Pers]){
             Asezat[Pers]=true;
             if(!Dusman[X[k-1]][Pers]){
                 if(k == N){
                    if(!--K){
                        Sol();
                        return;
                    }
                 }
                 else{
                    Back(k+1);
                 }
             }
             Asezat[Pers]=false;
         }
     }
 }

int main()
{
fin>>N>>K>>M;
for(int i=1 ; i<=M ; i++){
     int Pers1 , Pers2;
     fin>>Pers1>>Pers2;
     Dusman[Pers1][Pers2]=true;
     Dusman[Pers2][Pers1]=true;
 }

Back(1);
return 0;
}