比赛 |
20111104 |
评测结果 |
AWWAWWWAWA |
题目名称 |
运输公司 |
最终得分 |
40 |
用户昵称 |
lizhe |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-04 21:28:42 |
显示代码纯文本
program transz;
const
maxtin=10000000;
var
i,j,l,n,m,k,e,q,p,a,b,c,min,minn,cost:longint;
change:boolean;
map,w:array[1..100,1..100]of longint;
pre,last:array[0..100]of longint;
flag:array[1..100]of boolean;
no:array[1..100000,1..3]of longint;
d:array[1..100]of longint;
procedure init;
begin
assign(input,'transz.in');
reset(input);
assign(output,'transz.out');
rewrite(output);
read(n,m,k,e);
for i:=1 to m do
for j:=1 to m do
if i<>j then
map[i,j]:=maxtin;
for i:=1 to e do
begin
read(a,b,c);
map[a,b]:=c;
map[b,a]:=c
end;
read(q);
for i:=1 to q do
begin
read(c,a,b);
no[i,1]:=c;
no[i,2]:=a;
no[i,3]:=b
end;
fillchar(last,sizeof(last),true)
end;
procedure yuchuli;
var
l1,l2:longint;
begin
fillchar(flag,sizeof(flag),true);
for j:=1 to q do
if (l>=no[j,2]) and (l<=no[j,3]) then
flag[no[j,1]]:=false;
for l1:=1 to m do
for l2:=1 to m do
if (flag[l1]=false) or (flag[l2]=false) then
w[l1,l2]:=maxtin
else w[l1,l2]:=map[l1,l2];
fillchar(flag,sizeof(flag),true);
change:=false;
for j:=1 to m do
d[j]:=w[1,j]
end;
procedure dijkstra;
begin
for i:=1 to m-1 do
begin
min:=maxtin;
for j:=1 to m do
if (min>d[j]) and flag[j] then
begin
min:=d[j];
minn:=j
end;
flag[minn]:=false;
for j:=1 to m do
if d[j]>d[minn]+w[minn,j] then
begin
d[j]:=d[minn]+w[minn,j];
pre[j]:=minn
end
end
end;
procedure panduan;
var
x,y:longint;
begin
x:=pre[m];
y:=last[m];
repeat
if x<>y then
begin
change:=true;
break
end;
x:=pre[x];
y:=last[y]
until x=0;
for j:=1 to m do
last[j]:=pre[j]
end;
procedure jisuan;
begin
cost:=cost+d[m];
if change then cost:=cost+k
end;
procedure main;
begin
for l:=1 to n do
begin
yuchuli;
dijkstra;
panduan;
jisuan
end
end;
procedure print;
begin
writeln(cost-k);
close(input);
close(output)
end;
begin
init;
main;
print
end.