划重点007 发现不存在两条路通向同一扇门。
最后一个超时了 暂时没想到该如何优化 如果有uu会了欢迎指教
参考博文
n=int(input())
pre=[0 for i in range(n+1)]
res=[]
for i in range(1,1+n):
tep=list(map(int,input().split()))
if tep[0]==0:
res.append(i)
continue
else:
for j in tep[1:]:
pre[j]=i
ma=0
index=1
for i in res:
cn=0
k=i
while(pre[k]!=0):
k=pre[k]
cn+=1
if cn>ma:
ma=cn
index=i
print(index)