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 1227. Rally Championship

Help!
Posted by romiohoo 26 Jan 2003 17:33
Why I've got WA?
program p1227;
var
  g:array[1..100,1..100]of integer;
  a:array[1..100,1..100]of 0..2;
  visited:array[1..100]of boolean;
  s,total:longint;
  i,j,m,n,c1,c2,len:integer;
procedure exchange(c1,c2:integer);
var
  temp:integer;
begin
  if c1>c2 then
    begin
      temp:=c1;
      c1:=c2;
      c2:=temp
    end
end;
procedure search(i:integer);
var
  j:integer;
begin
  for j:=1 to n do
    begin
      if (a[i,j]=0)and(g[i,j]<>0) then
        begin
          if visited[j] then
            begin
              writeln('YES');
              halt
            end
          else
            begin
              visited[j]:=true;
              total:=total+g[i,j];
              a[i,j]:=1;
              a[j,i]:=1;
              if total>s then
                begin
                  writeln('YES');
                  halt
                end
              else
                begin
                  search(j);
                  visited[j]:=false;
                  total:=total-g[i,j];
                  a[i,j]:=0;
                  a[j,i]:=0
                end
            end
        end
    end
end;
begin
  fillchar(g,sizeof(g),0);
  fillchar(a,sizeof(a),2);
  fillchar(visited,sizeof(visited),false);
  readln(m,n,s);
  for i:=1 to n do
    begin
      readln(c1,c2,len);
      g[c1,c2]:=len;
      g[c2,c1]:=len;
      if a[c1,c2]=1 then
        begin
          writeln('YES');
          halt
        end;
      a[c1,c2]:=0;
      a[c1,c2]:=0
    end;
  for i:=1 to n do
    begin
      visited[i]:=true;
      search(i);
      visited[i]:=false
    end;
  writeln('NO')
end.