Cod sursa(job #188419)

Utilizator fogabFodor Gabor fogab Data 8 mai 2008 11:24:12
Problema Dusman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>

#define LL long long

using namespace std;

int A[1001][4],a,b,h;
int gen[1001],C,cut[1001],N,K,M;

int main(void){

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

in >> N >> K >> M;
for (;M;M--){
    in >> a >> b;
    A[a][0]++;
    A[a][A[a][0]] = b;
    A[b][0]++;
    A[b][A[b][0]] = a;
    }
C = 1;
gen[0] = 0;
cut[0] = 1;
gen[1] = 0;
bool ok;
while (K){      
      if (C == N+1){
         K--;
         C--;       
         }
      else{
         cut[gen[C]] = 0;
         cut[0] = 1;
         h = gen[C]+1;
         while (h<=N && ((cut[h]==1) ||
                A[gen[C-1]][1]==h || 
                A[gen[C-1]][2]==h || 
                A[gen[C-1]][3]==h)) h++;
         //out << h << " " << C << "\n";
         if (h == N+1){
            gen[C] = 0;
            C--;
            }
         else{
            cut[h] = 1;
            gen[C] = h;
            C++;   
         }
         }   
      }

for (int i=1;i<=N;i++)
    out << gen[i] << " ";

in.close();
out.close();

return 0;

}