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 1077. Travelling Tours

WA2
Posted by remdy21 29 Jul 2010 19:59
why WA2??
program ural;
var n,a,b,y:byte;
    m,i,z,r:integer;
    h,g:array[1..200]of integer;
    t:array[1..32767]of byte;
    l:array[1..32767]of integer;
    p,q:array[1..32767]of boolean;
    s:array[1..200]of byte;
    k:array[1..400]of integer;
    o:array[1..400]of byte;
    u:array[1..200]of boolean;
    x:boolean;
procedure search(d:byte);
var r:integer;
  begin
    u[d]:=true;
    r:=h[d];
    while r<>0 do
      begin
        if u[t[r]]=false then
          begin
            inc(y);
            k[y]:=g[d];
            g[d]:=y;
            o[y]:=t[r];
            inc(y);
            k[y]:=g[t[r]];
            g[t[r]]:=y;
            o[y]:=d;
            p[r]:=true;
            if q[r] then
              p[r+1]:=true
            else
              p[r-1]:=true;
            search(t[r]);
          end;
        r:=l[r];
      end;
  end;
procedure track(v,d:byte);
var r:byte;
  begin
    if d=i then
      begin
        write(v,' ');
        for r:=1 to v-1 do
          write(s[r],' ');
        writeln(d);
        x:=true;
        exit;
      end;
    u[d]:=true;
    s[v]:=d;
    r:=g[d];
    while r<>0 do
      begin
        if u[o[r]]=false then
          track(v+1,o[r]);
        if x then
          exit;
        r:=k[r];
      end;
  end;
begin
  assign(input,'travel.in');
  assign(output,'travel.out');
  reset(input);
  rewrite(output);
  readln(n,m);
  for i:=1 to m do
    begin
      readln(a,b);
      inc(r);
      l[r]:=h[a];
      h[a]:=r;
      t[r]:=b;
      q[r]:=true;
      inc(r);
      l[r]:=h[b];
      h[b]:=r;
      t[r]:=a;
    end;
  z:=m-n;
  for i:=1 to n do
    if u[i]=false then
      begin
        inc(z);
        search(i);
      end;
  if z<=0 then
    begin
      writeln(0);
      exit;
    end
  else
    writeln(z);
  for i:=1 to n do
    begin
      r:=h[i];
      while r<>0 do
        begin
          if(q[r])and(p[r]=false)then
            begin
              x:=false;
              fillchar(u,sizeof(u),false);
              track(1,t[r]);
            end;
          r:=l[r];
        end;
    end;
end.