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

Common Board

What is a trick in a task B? (+) Why my program WA? Tell me, please
Posted by TUP#1 - We hate PIBAS 12 Oct 2002 17:02
CONST Dim = 31;
      INF = 1000000000;

VAR D:Array[0..Dim,0..Dim,0..Dim] of longint;
    P:Array[1..Dim] of integer;
    R:Array[0..Dim,0..Dim] of longint;
    NL:integer;

PROCEDURE ReadData;
var K,i,j:integer;
begin
  for i:=0 to Dim do
    for j:=0 to Dim do
      for k:=0 to Dim do D[i,j,k]:=INF;

  readln(NL);
  for i:=1 to NL do
  begin
    readln(P[i]);
    for j:=1 to P[i] do
    begin
      repeat
        read(K);
        if K=0 then break;
        read(D[i-1,K,j]);
      until false;
      readln;
    end;
    readln;
  end;
end;

PROCEDURE Solve;
var Best,L,k,i,j,dd:longint;
begin
  for i:=0 to Dim do
    for j:=0 to Dim do R[i,j]:=INF;
  for i:=1 to P[1] do R[1,i]:=D[0,1,i];
  for L:=1 to NL-1 do
    for j:=1 to P[L] do
      if R[L,j]<>INF then
        for k:=1 to P[L+1] do
        begin
          dd:=R[L,j]+D[L,j,k];
          if dd<R[L+1,k] then R[L+1,k]:=dd;
        end;
  Best:=INF;
  for i:=1 to P[NL] do
    if R[NL,i]<Best then Best:=R[NL,i];
  writeln(Best);
end;

BEGIN
  ReadData;
  Solve;
END.