Cod sursa(job #120444)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 5 ianuarie 2008 15:09:31
Problema Dusman Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.05 kb
program alex;
var f:text;
    e:boolean;
    n,m,k,i,j,q,w,d:longint;
    a:array[1..1000,0..3]of integer;
    b,c:array[1..1000]of integer;
begin
assign(f,'dusman.in');reset(f);
readln(f,n,k,m);
for i:=1 to m do
    begin
    read(f,q,w);
    a[q,0]:=a[q,0]+1;
    a[q,a[q,0]]:=w;
    a[w,0]:=a[w,0]+1;
    a[w,a[w,0]]:=q;
    end;
close(f);
d:=0;
for i:=1 to n do
    b[i]:=1;
repeat
j:=n;
repeat
if b[j]=n then begin
               b[j]:=1;
               j:=j-1;
               end;
until b[j]<>n;
b[j]:=b[j]+1;
for i:=1 to n do
    c[i]:=0;
for i:=1 to n do
    c[b[i]]:=c[b[i]]+1;
i:=0;
e:=true;
repeat
i:=i+1;
if c[i]<>1 then e:=false;
until(e=false)or(i=n);
if e then begin
          i:=1;
          e:=true;
          repeat
          i:=i+1;
          if(a[b[i],1]=b[i-1])or(a[b[i],2]=b[i-1])or(a[b[i],3]=b[i-1]) then e:=false;
          until(e=false)or(i=n);
          if e=true then d:=d+1;
          end;
until k=d;
assign(f,'dusman.out');rewrite(f);
for i:=1 to n do
    write(f,b[i],' ');
close(f);
end.