第三题 from collections import defaultdict import heapq class Node(object): def __init__(self,time,l,index): self.time = time self.l = l self.index = index def __lt__(self, other): if self.time < other.time: return True elif self.time == other.time: return self.index < other.index else: return False N,M = map(int, input().split()) times = list(map(int, input().split())) d = defaultdict(set) l = [] #heapq.heapify(l) for i in range(M): tmp = list(map(int, input().split())) for e in tmp[:-1]: d[tmp[-1]].add(e) for i in range(N): #print(times[i], d[i+1],i+1) heapq.heappush(l,Node(times[i], d[i+1], i+1)) res = [] while len(l) > 0: tmp = [] node = None while len(l) > 0: node = heapq.heappop(l) if len(node.l) > 0: tmp.append(node) else: res.append(node.index) break for e in tmp: heapq.heappush(l, e) if node != None: for i in range(len(l)): if node.index in l[i].l: l[i].l.remove(node.index) for e in res: print(e, end=" ")
点赞 评论

相关推荐

03-17 15:08
已编辑
腾讯_后端开发(准入职员工)
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客企业服务