結果
問題 | No.2325 Skill Tree |
ユーザー |
|
提出日時 | 2023-05-28 14:46:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,347 ms / 3,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 627 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 126,016 KB |
最終ジャッジ日時 | 2024-12-27 02:57:13 |
合計ジャッジ時間 | 37,413 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
import bisectN = int(input())needLV = [-1 for i in range(0,N+1)]needLV[1] = 0data = {}LV = [0,0]for i in range(1,N+1):data[i] = []for i in range(N-1):L,A = map(int,input().split())data[A].append(i+2)LV.append(L)#print(data)nex = [1]visited = [0 for i in range(0,N+1)]while nex != []:nex2 = []for i in nex:visited[i] = 1for j in data[i]:if visited[j] == 0:needLV[j] = max(LV[i],LV[j],needLV[i])nex2.append(j)nex = nex2.copy()Q = int(input())bisect_lis = []for i in range(0,len(needLV)):if needLV[i] == -1:bisect_lis.append(10**10)else:bisect_lis.append(needLV[i])bisect_lis = sorted(bisect_lis)for i in range(Q):num,sub = map(int,input().split())if num == 1:print(bisect.bisect_right(bisect_lis,sub))else:print(needLV[sub])