比赛 |
20110414pm |
评测结果 |
AEWTTTTEEE |
题目名称 |
龙凡 |
最终得分 |
10 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-04-14 16:19:15 |
显示代码纯文本
const
oo=99999999;
var
n,m:longint;
g,a:array[0..100000,0..30]of longint;
last,d:array[1..1000000]of longint;
v:array[1..1000000]of boolean;
q:array[1..1000000]of longint;
procedure init;
var
i,j,x,y,z:longint;
begin
assign(input,'travel.in'); reset(input);
assign(output,'travel.out'); rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(x,y,z);
inc(g[x,0]);
g[x,g[x,0]]:=y;
inc(g[y,0]);
g[y,g[y,0]]:=x;
inc(a[x,0]);
a[x,a[x,0]]:=z;
inc(a[y,0]);
a[y,a[y,0]]:=z;
end;
end;
procedure spfa;
var
h,t,x,i,y:longint;
begin
h:=1;
t:=1;
for i:=1 to n do
begin
v[i]:=false;
d[i]:=oo;
end;
d[1]:=0;
v[1]:=true;
q[1]:=1;
repeat
x:=q[h];
for i:=1 to g[x,0] do
begin
y:=g[x,i];
if d[x]+a[x,i]<d[y] then
begin
d[y]:=d[x]+a[x,i];
last[y]:=x;
if not v[y] then
begin
v[y]:=true;
inc(t);
q[t]:=y;
end;
end;
end;
inc(h);
v[x]:=false;
until h>t;
end;
procedure main;
var
i,k,j,z:longint;
begin
for i:=2 to n do
begin
k:=last[i];
for j:=1 to g[k,0] do
if g[k,j]=i then
begin
z:=a[k,j];
a[k,j]:=oo;
break;
end;
spfa;
for j:=1 to g[k,0] do
if g[k,j]=i then
begin
a[k,j]:=z;
break;
end;
if d[i]=oo then writeln(-1)
else writeln(d[i]);
end;
end;
begin
init;
spfa;
main;
close(input);
close(output);
end.