比赛 |
20110722 |
评测结果 |
AWAWAWAAAAAAAAAAA |
题目名称 |
网络探测 |
最终得分 |
82 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-22 10:15:04 |
显示代码纯文本
program ping;
const
maxn=1100;
maxm=1001000;
type
node=record
v,w,next:longint;
end;
var
dist,list,q:array[0..maxn] of longint;
map:array[0..maxm] of node;
b,bb:array[0..maxn] of boolean;
n,m,i,j,u,v,r1,r2,r3,h,t,e:longint;
procedure addedge(i,j,w:longint);
begin
inc(e);
map[e].v:=j;
map[e].w:=w;
map[e].next:=list[i];
list[i]:=e;
inc(e);
map[e].v:=i;
map[e].w:=w;
map[e].next:=list[j];
list[j]:=e;
end;
begin
assign(input,'ping.in');
reset(input);
assign(output,'ping.out');
rewrite(output);
readln(n,m,v);
if v=0 then
begin
writeln(0);
close(input);
close(output);
halt;
end;
e:=0;
fillchar(list,sizeof(list),0);
for i:=1 to m do
begin
readln(r1,r2,r3);
addedge(r1,r2,r3);
end;
fillchar(dist,sizeof(dist),0);
fillchar(bb,sizeof(bb),false);
fillchar(b,sizeof(b),false);
b[0]:=true;
bb[0]:=true;
q[1]:=0;
h:=0;
t:=1;
while h<>t do
begin
h:=(h+1) mod n;
i:=q[h];
u:=list[i];
while u<>0 do
begin
j:=map[u].v;
if (not bb[j]) or (dist[i]+map[u].w<dist[j]) then
begin
dist[j]:=dist[i]+map[u].w;
bb[j]:=true;
if not b[j] then
begin
b[j]:=true;
t:=(t+1) mod n;
q[t]:=j;
end;
end;
u:=map[u].next;
end;
b[i]:=false;
end;
if dist[v]>0
then writeln(dist[v])
else writeln('no');
close(input);
close(output);
end.