結果
問題 |
No.2325 Skill Tree
|
ユーザー |
![]() |
提出日時 | 2023-05-28 15:13:09 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 849,320 KB |
最終ジャッジ日時 | 2024-12-27 05:12:43 |
合計ジャッジ時間 | 27,895 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 RE * 23 MLE * 3 |
ソースコード
import heapq import bisect N = int(input()) skill = [] for i in range(N-1): L,A = map(int,input().split()) skill.append([L,A]) #print(skill) p = [[] for i in range(N)] for i in range(N-1): p[skill[i][1]-1].append(i+1) que = [] heapq.heapify(que) heapq.heappush(que,[1,0]) seen = [-1]*N seen[0] = 1 #print(que) level = 0 while que: l, now = heapq.heappop(que) if level <= l: level = l seen[now] = level for next in p[now]: heapq.heappush(que,[skill[next-1][0],next]) M = max(seen) table = [0]*(M+1) for i in seen: if i == -1: continue table[i] += 1 for i in range(M): table[i+1] += table[i] levellist = sorted(seen) cnt = seen.count(-1) Q = int(input()) for q in range(Q): a = list(map(int,input().split())) #print(a) if a[0] == 1: print(bisect.bisect_right(levellist,a[1])-cnt) else: print(seen[a[1]-1])