比赛 |
20091019练习题 |
评测结果 |
AAAAAAAAAA |
题目名称 |
奶牛跨栏 |
最终得分 |
100 |
用户昵称 |
belong.zmx |
运行时间 |
0.275 s |
代码语言 |
Pascal |
内存使用 |
0.51 MiB |
提交时间 |
2009-10-19 21:01:02 |
显示代码纯文本
program hurdles(input,output);
var
a:array[1..300,1..300]of longint;
i,j,k,h:integer;
n,m,t,ai,bi:integer;
si,ei,hi:longint;
function judge(x,y:longint):longint;
begin
if x>y then judge:=x
else judge:=y;
end;
begin
assign(input,'hurdles.in');
reset(input);
assign(output,'hurdles.out');
rewrite(output);
readln(n,m,t);
for i:=1 to n do
for j:=1 to n do
a[i,j]:=1000001;
for i:=1 to m do
begin
readln(si,ei,hi);
a[si,ei]:=hi;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (a[i,j]=1000001)or(judge(a[i,k],a[k,j])<a[i,j]) then
a[i,j]:=judge(a[i,k],a[k,j]);
for h:=1 to t do
begin
readln(ai,bi);
if a[ai,bi]=1000001 then writeln('-1')
else writeln(a[ai,bi]);
end;
close(input);
close(output);
end.