結果

問題 No.2325 Skill Tree
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2023-05-28 15:28:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 543 ms / 3,000 ms
コード長 753 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 121,632 KB
最終ジャッジ日時 2023-08-27 12:15:24
合計ジャッジ時間 17,468 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,604 KB
testcase_01 AC 93 ms
71,420 KB
testcase_02 AC 95 ms
71,652 KB
testcase_03 AC 98 ms
71,568 KB
testcase_04 AC 95 ms
71,660 KB
testcase_05 AC 93 ms
71,832 KB
testcase_06 AC 95 ms
71,416 KB
testcase_07 AC 208 ms
90,856 KB
testcase_08 AC 219 ms
93,160 KB
testcase_09 AC 240 ms
93,868 KB
testcase_10 AC 280 ms
105,104 KB
testcase_11 AC 260 ms
98,900 KB
testcase_12 AC 399 ms
119,816 KB
testcase_13 AC 392 ms
119,728 KB
testcase_14 AC 403 ms
118,416 KB
testcase_15 AC 410 ms
117,628 KB
testcase_16 AC 404 ms
118,192 KB
testcase_17 AC 395 ms
116,436 KB
testcase_18 AC 386 ms
116,600 KB
testcase_19 AC 390 ms
116,704 KB
testcase_20 AC 383 ms
116,720 KB
testcase_21 AC 385 ms
116,540 KB
testcase_22 AC 410 ms
119,940 KB
testcase_23 AC 407 ms
120,196 KB
testcase_24 AC 404 ms
119,976 KB
testcase_25 AC 394 ms
118,216 KB
testcase_26 AC 405 ms
118,180 KB
testcase_27 AC 543 ms
120,404 KB
testcase_28 AC 524 ms
119,664 KB
testcase_29 AC 515 ms
119,808 KB
testcase_30 AC 519 ms
119,284 KB
testcase_31 AC 526 ms
119,128 KB
testcase_32 AC 480 ms
116,752 KB
testcase_33 AC 499 ms
118,212 KB
testcase_34 AC 490 ms
117,020 KB
testcase_35 AC 510 ms
120,588 KB
testcase_36 AC 516 ms
121,452 KB
testcase_37 AC 521 ms
121,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
import bisect
from collections import deque

N = int(stdin.readline())

L = [0] + [float("inf")] * (N-1)

lis = [ [] for i in range(N) ]

for i in range(N-1):

    l,a = map(int,stdin.readline().split())
    a -= 1
    lis[a].append( (i+1,l) )

q = deque([0])
while q:
    v = q.popleft()
    for nex,cost in lis[v]:
        L[nex] = max(L[v] , cost)
        q.append(nex)

L2 = [i for i in L]
L2.sort()

Q = int(stdin.readline())

ANS = []
for loop in range(Q):

    ty,x = map(int,stdin.readline().split())

    if ty == 1:
        idx = bisect.bisect_right(L2,x)
        ANS.append(idx)
    else:
        if L[x-1] == float("inf"):
            ANS.append(-1)
        else:
            ANS.append(L[x-1])

print (*ANS,sep="\n")
0