結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
pratica
|
| 提出日時 | 2023-05-28 15:20:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,694 ms / 3,000 ms |
| コード長 | 774 bytes |
| コンパイル時間 | 451 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 121,328 KB |
| 最終ジャッジ日時 | 2024-12-27 06:11:02 |
| 合計ジャッジ時間 | 36,732 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
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])
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])
pratica