比赛 20110722 评测结果 AWAAAAAAAWAAAAAWA
题目名称 网络探测 最终得分 82
用户昵称 ZhouHang 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-22 11:39:42
显示代码纯文本
Program ping;
Const
	inf = 'ping.in';
	ouf = 'ping.out';

Var
	n,m,t,ans : longint;
	dis,pre : array [0..1020] of longint;
	v : array [0..1020] of boolean;
	list : array [0..100000] of longint;
	a : array [0..1020,0..1020] of longint;

Procedure Init;
	Var
		i,j,x,y,z : longint;
	Begin
		readln(n,m,t);

		for i := 0 to n-1 do
			for j := 0 to n-1 do
				a[i,j] := maxlongint div 2;
		for i := 1 to m do
			Begin
				readln(x,y,z);
                                if z<a[x,y] then
				 begin
                                  a[x,y] := z;
                                  a[y,x] := z;
                                 end;
			End;

	End;


Procedure Spfa;
	Var
		i,open,closd,tn : longint;
	Begin
		fillchar(list,sizeof(list),0);
                fillchar(v,sizeof(v),false);
                for i := 1 to n-1 do dis[i] := maxlongint div 2;
                dis[0] := 0;
		for i := 1 to n-1 do pre[i] := maxlongint;
                pre[0] := 0;
		list[1] := 0; v[0] := true;
		open := 1; closd := 0;
		while closd<open do
			Begin
				inc(closd);
				v[closd] := false;
				tn := list[closd];
				for i := 0 to n-1 do
                                        if dis[i]>dis[tn]+a[tn,i]
						then begin
							dis[i] := dis[tn]+a[tn,i];
							pre[i] := tn;
							if (not v[i]) then
								begin
									v[i] := true;
									inc(open);
									list[open] := i;
								end;
							end;
			End;
	End;

Procedure Findnum(t : longint);
        Begin
		if t=0 then exit
                        else inc(ans);
		Findnum(pre[t]);
	End;



Begin
	Assign(input,inf); Reset(input);
	Assign(output,ouf); Rewrite(output);


	Init;

	Spfa;

        ans := 0;
        Findnum(t);

        if dis[t]=maxlongint div 2
          then begin
                writeln('no');
                Close(input); Close(output);
                Halt;
               end;
	if ans>=10
		then writeln('no')
		else writeln(dis[t]);

	Close(input); Close(output);
End.