VDANGER - Nguy hiểm rõ ràng trước mắt
Tác giả: ll931110
Ngôn ngữ: Pascal
Program VDANGER;
Const
input = '';
output = '';
Var
a: array[1..10000] of longint;
n,m: longint;
c: array[1..100,1..100] of longint;
Procedure init;
Var
f: text;
i,j: longint;
Begin
Assign(f, input);
Reset(f);
Readln(f, n, m);
For i:= 1 to m do readln(f, a[i]);
For i:= 1 to n do
Begin
For j:= 1 to n do read(f, c[i,j]);
Readln(f);
End;
Close(f);
End;
Procedure Floyd;
Var
k,u,v: longint;
Begin
For k:= 1 to n do
For u:= 1 to n do
For v:= 1 to n do
if c[u,v] > c[u,k] + c[k,v] then
c[u,v]:= c[u,k] + c[k,v];
End;
Procedure solve;
Var
f: text;
sum,i: longint;
Begin
Assign(f, output);
Rewrite(f);
sum:= 0;
For i:= 1 to m - 1 do
sum:= sum + c[a[i],a[i + 1]];
Writeln(f, sum);
Close(f);
End;
Begin
init;
Floyd;
solve;
End.