题面:

思路:

 

代码:

uses math;
var ans,n,m,tot,x,y,i,j:longint;
 next,last,tail:array[0..100005] of longint;
  t,c,d:array[0..10005] of longint;
   f:Array[0..10005] of boolean;

procedure add(x,y:longint);
begin
 inc(tot);
 next[tot]:=y;
 last[tot]:=tail[x];
 tail[x]:=tot;
end;

procedure dfs(x,y:longint);
var cc:longint;
begin
 c[x]:=max(c[x],y+t[x]);
 dec(d[x]);
 if d[x]=0 then
  begin
   cc:=tail[x];
   while (cc>0) do
    begin
     dfs(next[cc],c[x]);
     cc:=last[cc];
    end;
  end;
end;

begin

assign(input,'msched.in');
reset(input);
assign(output,'msched.out');
rewrite(output);

read(n,m);
for i:=1 to n do read(t[i]);
for i:=1 to m do begin read(x,y); add(x,y); f[y]:=true; inc(d[y]); end;

for i:=1 to n do
 if not f[i] then
  begin
   d[i]:=1;
   dfs(i,0);
  end;

for i:=1 to n do ans:=max(ans,c[i]);
writeln(ans);

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

 

posted on 2018-10-04 14:00  Tolye  阅读(109)  评论(0编辑  收藏  举报