st.evil吧 关注:5贴子:35
  • 1回复贴,共1
var a:array[1..10000,1..10000] of longint;
    r:array[1..10000] of longint;
    i,j,n,m,x,y,t,ans:longint;
procedure dijkstra(v:longint);
var d:array[1..10000] of longint;
    used:array[1..10000] of boolean;
    min,i,u,n:longint;
begin
  fillchar(d,sizeof(d),0);
  fillchar(used,sizeof(used),0);
  for i:=1 to n do d[i]:=a[v,i];
  repeat
    min:=maxint; u:=0;
    for i:=1 to n do
      if (not used[i])and(d[i]<min) then
      begin
        u:=i; min:=d[i];
      end;
    if u<>0 then
    begin
      used[u]:=true;
      for i:=1 to n do
        if (not used[i])and(a[u,i]+d[u]<d[i]) then d[i]:=a[u,i]+d[u];
    end;
  until u=0;
end;
begin
  readln(n,m);
  for i:=1 to n do
  begin
    readln(r[i]);
    a[i,i]:=0;
  end;
  for i:=1 to m do readln(x,y,a[x,y]);
  for i:=1 to n do
  begin
    dijkstra(i); t:=i;
    for j:=1 to n do
      if (r[j]<=r[t])and(a[i,j]<=a[i,t]) then inc(ans);
  end;
  writeln(ans);
end.


IP属地:中国香港1楼2008-05-27 22:07回复
    o(n^3)的烂算法。。


    IP属地:中国香港2楼2008-05-27 22:07
    回复