ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1040. Airline Company

Show all messages Hide all messages

help!where is my program wrong? girl 7 Feb 2003 08:06
type btype=record
       x,y:integer
       end;
var b,c:array[1..1000] of integer;
    a:array[1..1000] of btype;
    m,n,i:integer;
    v:array[1..1000] of boolean;
function ok(x,dep:integer):boolean;
var ff,min,t,f1,f2,i,j:integer;
    e:array[1..1000] of integer;
begin
  ok:=true;
  if b[a[x].x]=1 then
  begin
    t:=0;
    f1:=0;
    f2:=0;
    for i:=1 to dep-1 do
    if (a[c[i]].x=a[x].x) then
    begin
      inc(t);
      e[t]:=i;
      if i mod 2=0 then inc(f2)
      else inc(f1);
    end
    else if (a[c[i]].y=a[x].x) then
    begin
      inc(t);
      e[t]:=i;
      if i mod 2=0 then inc(f2)
      else inc(f1);
    end;
    inc(t);
    e[t]:=dep;
    if dep mod 2=0 then inc(f2)
    else inc(f1);
    if (t=1) then exit;
    if (t>=2) and (f1=0) then
    begin
      ok:=false;
      exit;
    end;
    min:=0;
    min:=e[1];
    for i:=2 to t do
    if e[i]<min then min:=e[i];
    if min=1 then exit;
    for i:=2 to min do
    begin
       ff:=0;
       for j:=1 to t do
       if e[j] mod i=0 then inc(ff)
       else break;
       if ff=t then
       begin
         ok:=false;
         exit;
       end;
    end;
    if b[a[x].y]=1 then
  begin
    t:=0;
    f1:=0;
    f2:=0;
    for i:=1 to dep-1 do
    if (a[c[i]].x=a[x].y) then
    begin
      inc(t);
      e[t]:=i;
      if i mod 2=0 then inc(f2)
      else inc(f1);
    end
    else if (a[c[i]].y=a[x].y) then
    begin
      inc(t);
      e[t]:=i;
      if i mod 2=0 then inc(f2)
      else inc(f1);
    end;
    inc(t);
    e[t]:=dep;
    if (t=1) then exit;
    if (t=2) and (f1=0) then
    begin
      ok:=false;
      exit;
    end;
    if (t>2) and (f1=0) then
    begin
      ok:=false;
      exit;
    end;
    min:=e[1];
    for i:=2 to t do
    if e[i]<min then min:=e[i];
    for i:=2 to min do
    begin
       ff:=0;
       for j:=1 to t do
       if e[j] mod i=0 then inc(ff)
       else break;
       if ff=t then
       begin
         ok:=false;
         exit;
       end;
    end;
end;
end;
end;
procedure search(dep:integer);
var i,j:integer;
begin
  for i:=1 to m do
  if ok(i,dep) and (v[i]=false) then
  begin
    v[i]:=true;
    c[dep]:=i;
    dec(b[a[i].x]);
    dec(b[a[i].y]);
    if dep=m then
    begin
      writeln('YES');
      for j:=1 to m do
        write(c[j]:5);
        halt;
    end
    else search(dep+1);
    c[dep]:=0;
    inc(b[a[i].x]);
    inc(b[a[i].y]);
    v[i]:=false;
  end;
end;
begin
  read(n,m);
  fillchar(v,sizeof(v),0);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  for i:=1 to m do
  begin
    read(a[i].x,a[i].y);
    inc(b[a[i].x]);
    inc(b[a[i].y]);
  end;
  search(1);
  writeln('NO');
end.