记录编号 1284 评测结果 AAAAAAAAAA
题目名称 找最佳通路 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 Pascal 运行时间 10.000 s
提交时间 2008-08-30 13:49:37 内存使用 0.00 MiB
显示代码纯文本
program cch(input,output);
var
 s:set of 1..50;
 a:array[1..50,1..50] of integer;
 djs:array[1..50] of integer;
 n,m,p,e,i,j,x,y,k,min:integer;
begin
 assign(input,'city.in');
 assign(output,'city.out');
 reset(input);
 rewrite(output);
 readln(n,m,p,e);
 for i:=1 to n do
  for j:=1 to n do a[i,j]:=maxint;
 for i:=1 to m do
  begin
   readln(x,y);
   a[x,y]:=1;
  end;
 for i:=1 to n do djs[i]:=a[p,i];
 s:=[p];
 for i:=1 to n-1 do
  begin
   k:=p;
   min:=maxint;
   for j:=1 to n do
    if not(j in s) and (min>djs[j]) then begin min:=djs[j]; k:=j; end;
   s:=s+[k];
   for j:=1 to n do
    if not(j in s) and (min+a[k,j]<djs[j]) then djs[j]:=a[k,j]+min;
  end;
 writeln(djs[e]+1);
 close(input);
 close(output);
end.