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

Why my program always got wrong answer,I tested it for any test case at my computer.it's perfect,it's okey,I can't understand!?!
Posted by hydra 22 Oct 2001 06:52
const maxn=100;maxl=100;
      price=4;
var a:array [1..maxn,1..maxn] of byte;
    bs,n,m,i,k,j,l:byte;
    s,route:array [1..maxl] of byte;
    money:array [1..maxn] of word;
    best,now:longint;
    flag:boolean;
begin
 readln(n,m);
 fillchar(a,sizeof(a),0);
 for i:=1 to m do
  begin
   read(l);
   for k:=1 to l do read(route[k]);
   readln;
   for k:=1 to l-1 do
    for j:=k+1 to l do
     a[route[k],route[j]]:=1;
  end;
 readln(m);
 for i:=1 to m do
  begin
   readln(money[i],s[i],j);
   if j=1 then money[i]:=65535;
  end;
 for k:=1 to n do
  for i:=1 to n do
   if a[i,k]<>0 then
    for j:=1 to n do
     if (a[k,j]<>0) and ((a[i,j]=0) or (a[i,k]+a[k,j]<a
[i,j]))
      then
       begin
        a[i,j]:=a[i,k]+a[k,j];
       end;
 for i:=1 to n do a[i,i]:=0;
 best:=2147483647;
 for i:=1 to n do
  begin
   flag:=true;now:=0;
   for k:=1 to m do
    if i<>s[k] then
     if (a[s[k],i]=0) or (a[s[k],i]*price>money[k])
      then begin flag:=false;break;end
   else if money[k]<>65535 then inc(now,a[s[k],i]);
   if flag then
    begin
     if now<best then
      begin best:=now;bs:=i;end;
    end;
  end;
 if best=2147483647 then writeln(0)
  else writeln(bs,' ',best*price);
end.