結果

問題 No.2325 Skill Tree
ユーザー qibqib
提出日時 2023-05-29 23:15:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,255 ms / 3,000 ms
コード長 812 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 120,520 KB
最終ジャッジ日時 2023-08-28 00:06:44
合計ジャッジ時間 33,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,384 KB
testcase_01 AC 75 ms
71,488 KB
testcase_02 AC 77 ms
71,640 KB
testcase_03 AC 74 ms
71,288 KB
testcase_04 AC 75 ms
71,416 KB
testcase_05 AC 75 ms
71,588 KB
testcase_06 AC 75 ms
71,600 KB
testcase_07 AC 442 ms
81,352 KB
testcase_08 AC 366 ms
88,896 KB
testcase_09 AC 495 ms
85,012 KB
testcase_10 AC 432 ms
95,952 KB
testcase_11 AC 506 ms
90,416 KB
testcase_12 AC 784 ms
102,920 KB
testcase_13 AC 802 ms
102,848 KB
testcase_14 AC 817 ms
102,908 KB
testcase_15 AC 811 ms
102,324 KB
testcase_16 AC 780 ms
102,352 KB
testcase_17 AC 776 ms
102,584 KB
testcase_18 AC 767 ms
102,528 KB
testcase_19 AC 779 ms
102,692 KB
testcase_20 AC 773 ms
102,488 KB
testcase_21 AC 768 ms
102,656 KB
testcase_22 AC 810 ms
102,696 KB
testcase_23 AC 792 ms
102,000 KB
testcase_24 AC 778 ms
102,668 KB
testcase_25 AC 765 ms
102,340 KB
testcase_26 AC 795 ms
102,552 KB
testcase_27 AC 1,255 ms
118,496 KB
testcase_28 AC 1,221 ms
118,708 KB
testcase_29 AC 1,202 ms
117,236 KB
testcase_30 AC 1,219 ms
119,676 KB
testcase_31 AC 1,244 ms
118,104 KB
testcase_32 AC 1,177 ms
120,464 KB
testcase_33 AC 1,128 ms
118,724 KB
testcase_34 AC 1,145 ms
119,464 KB
testcase_35 AC 1,233 ms
119,772 KB
testcase_36 AC 1,189 ms
120,520 KB
testcase_37 AC 1,226 ms
118,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import bisect as bs

INF = 1 << 60

n = int(input())

g = [[] for _ in range(n)]

for i in range(1, n):
  l, a = map(int, input().split())
  a -= 1
  g[a].append((i, l))

src = 0
dist = [INF for _ in range(n)]
dist[src] = 1
hp = [(1, src)]
while len(hp) > 0:
  cd, cur = heapq.heappop(hp)
  if cd > dist[cur]:
    continue
  for nxt, lv in g[cur]:
    if dist[nxt] <= max(dist[cur], lv):
      continue
    dist[nxt] = max(dist[cur], lv)
    heapq.heappush(hp, (dist[nxt], nxt))

items = []
for v in range(n):
  if dist[v] < INF:
    items.append(dist[v])

items.sort()

q = int(input())
for _ in range(q):
  t, x = map(int, input().split())
  if t == 1:
    i = bs.bisect_right(items, x)
    print(i)
  elif t == 2:
    x -= 1
    if dist[x] < INF:
      print(dist[x])
    else:
      print("-1")
0