关注
第三题 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=" ")
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 为了入行xx岗,我学了__ #
4966次浏览 95人参与
# 小厂实习有必要去吗 #
77941次浏览 368人参与
# 实习的你做了哪些离谱的工作 #
7696次浏览 109人参与
# Prompt分享 #
1688次浏览 53人参与
# 简历第一个项目做什么 #
6166次浏览 97人参与
# 你都见过什么样的草台班子? #
3696次浏览 41人参与
# 被说“做题家”,你的反应是_____? #
1294次浏览 49人参与
# 如果让你发明个APP,你会想做什么 #
1670次浏览 48人参与
# 听到哪句话代表面试稳了OR挂了? #
124671次浏览 559人参与
# 工作压力大,你会干什么? #
11476次浏览 272人参与
# 找实习记录 #
23527次浏览 407人参与
# 大家实习每天都在干啥 #
112345次浏览 606人参与
# 如果不上班,你会去做什么 #
5653次浏览 232人参与
# 邪修省钱套路 #
6483次浏览 218人参与
# AI让你的思考变深了还是变浅了? #
3874次浏览 110人参与
# 金三银四,你有感觉到吗 #
673462次浏览 6040人参与
# 分享一个让你热爱工作的瞬间 #
57163次浏览 482人参与
# 你想跟着什么样领导? #
45524次浏览 231人参与
# 我的求职精神状态 #
419467次浏览 3071人参与
# 通信硬件薪资爆料 #
1200612次浏览 7192人参与