比赛 20110722 评测结果 AWAWAWAAAAAAAAAAA
题目名称 网络探测 最终得分 82
用户昵称 Yoghurt 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-22 11:29:27
显示代码纯文本
program ping;
const
        filename='ping';
        oo=1000000000;
        maxn=2000;
type
        point=^node;
        node=record
                y,w:longint;
                next:point;
        end;
var
        list:array[0..maxn] of point;
        que,dis,count:array[0..maxn] of longint;
        flag:array[0..maxn] of boolean;
        n,m,s:longint;

procedure insert(x,y,w:longint);
var
         p:point;
begin
        new(p);
        p^.y:=y;
        p^.w:=w;
        p^.next:=list[x];
        list[x]:=p;
end;

procedure init;
var
   i,x,y,w:longint;
begin
        readln(n,m,s);
        for i:=1 to n do list[i]:=nil;
        for i:=1 to m do
        begin
                readln(x,y,w);
                insert(x,y,w);
                insert(y,x,w);
        end;
end;

procedure spfa(s:longint);
var
        p:point;
        x,y,head,tail,i:longint;
begin
        fillchar(flag,sizeof(flag),false);
        for i:=0 to n do dis[i]:=oo;
        fillchar(que,sizeof(que),0);
        head:=0; tail:=1;
        que[tail]:=s;
        inc(count[s]);
        flag[s]:=true;
        dis[s]:=0;
        while head<>tail do
        begin
                inc(head);
                if head>maxn then head:=1;
                x:=que[head];
                p:=list[x];
                while p<>nil do
                begin
                        y:=p^.y;
                        if dis[x]+p^.w<dis[y] then
                        begin
                                dis[y]:=dis[x]+p^.w;
                                if not flag[y] then
                                begin
                                        inc(tail);
                                        if tail>maxn then tail:=1;
                                        que[tail]:=y;
                                        inc(count[y]);
                                        if count[y]>10 then begin writeln('no'); close(input); close(output); halt; end;
                                        flag[y]:=true;
                                end;
                        end;
                        p:=p^.next;
                end;
                 flag[x]:=false;
        end;
end;

begin
        assign(input,filename+'.in'); reset(input);
        assign(output,filename+'.out'); rewrite(output);

        init;
        spfa(s);
        if dis[0]=oo then writeln('no')
                     else writeln(dis[0]);

        close(input); close(output);
end.