算法:图论(最短路)
分析:比较裸的最短路了,竟然错在了有向图上,导致此题本应AC的结果只拿了20分……恨!
program hldtymfs;
const
maxm=10000;
maxn=100;
diss:array [1..7] of longint=(2,6,4,8,6,10,14);
type
atp=record
y,dis,next:longint;
end;
var
tot,c,head,tail,start,finish:longint;
map:array [0..maxm] of atp;
que,first,v:array [0..maxn] of longint;
b:array [0..maxn] of boolean;
u:array [0..maxn] of 0..1;
procedure init;
var
i,x,y,dis:longint;
begin
tot:=0;
fillchar(v,sizeof(v),100);
for i:=1 to 7 do read(u[i]);
readln(start,finish);
readln(c);
for i:=1 to c do
begin
readln(x,y,dis);
inc(tot);
map[tot].y:=y;
if u[dis]=1 then map[tot].dis:=diss[dis] shr 1 else map[tot].dis:=diss[dis];
map[tot].next:=first[x];
first[x]:=tot;
inc(tot);
map[tot].y:=x;
if u[dis]=1 then map[tot].dis:=diss[dis] shr 1 else map[tot].dis:=diss[dis];
map[tot].next:=first[y];
first[y]:=tot;
end;
end;
procedure SPFA;
var
t:longint;
begin
head:=0;
tail:=1;
v[start]:=0;
que[1]:=start;
b[start]:=true;
while head<tail do
begin
inc(head);
t:=first[que[head]];
while t>0 do
begin
if v[que[head]]+map[t].dis<v[map[t].y] then
begin
v[map[t].y]:=v[que[head]]+map[t].dis;
if not b[map[t].y] then
begin
b[map[t].y]:=true;
inc(tail);
que[tail]:=map[t].y;
end;
end;
t:=map[t].next;
end;
b[que[head]]:=false;
end;
end;
begin
assign(input,'hldtymfs.in'); reset(input);
assign(output,'hldtymfs.out'); rewrite(output);
init;
SPFA;
writeln(v[finish]);
close(input); close(output);
end.