比赛 |
20110727 |
评测结果 |
AAAAAAAAA |
题目名称 |
道路重建 |
最终得分 |
100 |
用户昵称 |
lizhe |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-27 09:49:58 |
显示代码纯文本
program rebuild;
const
maxtin=1000000;
var
i,j,k,n,m,sum,min,a,b,c,d,s,e:longint;
map:array[1..100,0..100]of longint;
bad,f,w:array[1..100,1..100]of longint;
bool:array[1..100]of boolean;
procedure init;
begin
assign(input,'rebuild.in');
reset(input);
assign(output,'rebuild.out');
rewrite(output);
read(n,m);
for i:=1 to n do
for j:=1 to n do
if i<>j then
begin
f[i,j]:=maxtin;
w[i,j]:=maxtin
end;
for i:=1 to m do
begin
read(a,b,c);
f[a,b]:=c;
w[a,b]:=c;
inc(map[a,0]);
map[a,map[a,0]]:=b;
f[b,a]:=c;
w[b,a]:=c;
inc(map[b,0]);
map[b,map[b,0]]:=a
end;
read(d);
for i:=1 to d do
begin
read(a,b);
bad[a,b]:=1;
bad[b,a]:=1
end;
read(s,e);
fillchar(bool,sizeof(bool),true);
bool[s]:=false;
min:=maxtin
end;
procedure floyd;
begin
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if i<>j then
if f[i,j]>f[i,k]+f[k,j] then
f[i,j]:=f[i,k]+f[k,j]
end;
procedure dfs(vet:longint);
var
l:longint;
begin
if vet=e then
begin
if sum<min then
min:=sum
end
else
for l:=1 to map[vet,0] do
if (f[map[vet,l],e]<maxtin) and bool[map[vet,l]] then
begin
if bad[vet,map[vet,l]]=1 then
sum:=sum+w[vet,map[vet,l]];
bool[map[vet,l]]:=false;
dfs(map[vet,l]);
if bad[vet,map[vet,l]]=1 then
sum:=sum-w[vet,map[vet,l]];
bool[map[vet,l]]:=true;
end
end;
procedure print;
begin
writeln(min);
close(input);
close(output)
end;
begin
init;
floyd;
dfs(s);
print
end.