比赛 20110727 评测结果 AAAAAAAAA
题目名称 道路重建 最终得分 100
用户昵称 ZhouHang 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-27 11:41:06
显示代码纯文本
Program rebuild;
Const
	inf = 'rebuild.in';
	ouf = 'rebuild.out';

Var
	a,map : array [0..200,0..200] of longint;
       // f : array [0..200,0..200] of boolean;
	n,m,d,aa,bb : longint;

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

                fillchar(a,sizeof(a),10);
		for i := 1 to m do
		  begin
			readln(x,y,k);
                        map[x,y] := k;
			map[y,x] := k;
                        a[x,y]  := 0;
                        a[y,x] := 0;
		  end;
		readln(d);
		for i := 1 to d do
		  begin
			readln(x,y);
                        a[x,y] := map[x,y];
                        a[y,x] := map[y,x];
                  end;
		readln(aa,bb);

	End;

Function Min(x,y : longint): longint;
	Begin
		if x<y then exit(x);
		exit(y);
	End;

Procedure Floyd;
	Var
		k,i,j : longint;
	Begin
		for k := 1 to n do
		 for i := 1 to n do
		  for j := 1 to n do
			if (i<>j)and(i<>k)and(j<>k)
			  then a[i,j] := Min(a[i,j],a[i,k]+a[k,j]);
	End;

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

	Init;

	Floyd;

	writeln(a[aa,bb]);

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