文章
1
粉丝
70
获赞
1
访问
4.5k
from collections import defaultdict import heapq n,m=map(int,input().split()) a=list(map(int,input().split())) E = defaultdict(list) Eprev = defaultdict(list) cnt = defaultdict(int) out = defaultdict(int) for _ in range(m): u,v = map(int, input().split()) E[u].append(v) Eprev[v].append(u) cnt[v]+=1 out[u]+=1 ans = 0 count = 0 f = [0]*n #最早结束时间 q = [] for i in range(1,1+n): if cnt[i]==0: q.append((a[i-1], i)) # 最早结束时间,i heapq.heapify(q) while q: cur_time, node = heapq.heappop(q) f[node-1] = cur_time ans = max(ans, cur_time) for nxt in E[node]: cnt[nxt]-=1 if cnt[nxt]==0: heapq.heappush(q, (cur_time+a[nxt-1], nxt)) print(ans) idx = [] g = [ans]*n # 最晚结束时间 q = [] for i in range(n): if out[i+1]==0: # 后继没点了 q.append(i+1) while q: t = [] for i in q: for prev in Eprev[i]: g[prev-1] = min(g[prev-1], g[i-1]-a[i-1]) out[prev]-=1 if out[prev]==0: t.append(prev) q = t total = 1 mod = 10**9+7 for gi,fi i...
登录后发布评论
暂无评论,来抢沙发