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 1085. Meeting

HELP!Why does my program get WA?
Posted by Sam Koo 13 May 2002 19:15
My program gets "WA". I can't find what's wrong with it. Please help
me. Thank you!

program u1085;

var
  link :array[1..100,1..100] of boolean;
  pp,ppa   :integer;
  dist :array[1..100] of integer;
  n,k,v,u:integer;
  st   :array[1..100] of integer;
  money:array[1..100] of integer;
  okay :boolean;
  sum,summ  :longint;
  q    :array[1..100] of integer;


procedure init;

var
  m,u,l,v,w,bb  :integer;
  te  :array[1..100] of integer;


begin
{  assign(input,'u1085.in');
  reset(input);}
  readln(n,m);
  fillchar(link,sizeof(link),false);
  for u:=1 to m do begin
    read(l);
    for v:=1 to l do read(te[v]);
    readln;
    for v:=1 to l-1 do
      for w:=v+1 to l do begin
        link[te[v],te[w]]:=true;
        link[te[w],te[v]]:=true;
    end;
  end;
  readln(k);
  u:=1;
  while u<=k do begin
    readln(money[u],st[u],bb);
    if bb=1 then dec(k) else inc(u);
  end;
{  close(input);}
end;


procedure workpath;

var
  u,v,i,j  :integer;

begin
  fillchar(dist,sizeof(dist),$FF);
  fillchar(q,sizeof(q),0);
  i:=1; j:=1; q[1]:=pp; dist[pp]:=0;
  repeat
    for u:=1 to n do if (link[q[i],u]) and (dist[u]=-1) then begin
      dist[u]:=dist[q[i]]+1;
      inc(j);
      q[j]:=u;
    end;
    inc(i);
  until i>j;
end;



begin
  init;
  summ:=maxlongint;
  for pp:=1 to n do begin
    workpath;
    okay:=true;
    for u:=1 to k do begin
      if dist[st[u]]=-1 then begin
        okay:=false;
        break;
      end;
      if dist[st[u]]*4>money[u] then begin
        okay:=false;
        break;
      end;
    end;
    if okay then begin
      sum:=0;
      for u:=1 to k do sum:=sum+dist[st[u]]*4;
      if sum<summ then begin summ:=sum; ppa:=pp; end;
    end;
  end;
  if summ=maxlongint then writeln(0) else writeln(ppa,' ',summ);
end.