結果

問題 No.2325 Skill Tree
ユーザー rlangevinrlangevin
提出日時 2023-05-31 12:18:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 690 ms / 3,000 ms
コード長 707 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 113,172 KB
最終ジャッジ日時 2023-08-28 01:27:55
合計ジャッジ時間 22,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,376 KB
testcase_01 AC 77 ms
71,224 KB
testcase_02 AC 75 ms
71,444 KB
testcase_03 AC 77 ms
71,328 KB
testcase_04 AC 79 ms
71,196 KB
testcase_05 AC 78 ms
71,380 KB
testcase_06 AC 77 ms
71,236 KB
testcase_07 AC 185 ms
82,072 KB
testcase_08 AC 201 ms
88,024 KB
testcase_09 AC 209 ms
85,140 KB
testcase_10 AC 261 ms
94,312 KB
testcase_11 AC 243 ms
89,956 KB
testcase_12 AC 377 ms
102,296 KB
testcase_13 AC 374 ms
102,120 KB
testcase_14 AC 382 ms
103,108 KB
testcase_15 AC 381 ms
102,712 KB
testcase_16 AC 371 ms
102,112 KB
testcase_17 AC 350 ms
101,344 KB
testcase_18 AC 352 ms
101,384 KB
testcase_19 AC 357 ms
101,100 KB
testcase_20 AC 356 ms
101,612 KB
testcase_21 AC 353 ms
101,652 KB
testcase_22 AC 376 ms
103,220 KB
testcase_23 AC 386 ms
103,760 KB
testcase_24 AC 369 ms
103,116 KB
testcase_25 AC 363 ms
102,920 KB
testcase_26 AC 368 ms
103,160 KB
testcase_27 AC 650 ms
112,476 KB
testcase_28 AC 677 ms
112,248 KB
testcase_29 AC 690 ms
112,260 KB
testcase_30 AC 688 ms
112,292 KB
testcase_31 AC 662 ms
113,036 KB
testcase_32 AC 614 ms
112,456 KB
testcase_33 AC 634 ms
111,760 KB
testcase_34 AC 641 ms
111,996 KB
testcase_35 AC 685 ms
112,896 KB
testcase_36 AC 686 ms
112,880 KB
testcase_37 AC 689 ms
113,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import *
from bisect import *

N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    L, A = map(int, input().split())
    A -= 1
    G[A].append((i + 1, L))

H = [(0, 0)]
X, Y = [], [-1] * N
now = 0
flag = 1
while H:
    c, u = H[0]
    if flag:
        if c <= now:
            heappop(H)
            for v, cc in G[u]:
                heappush(H, (cc, v))
            Y[u] = now
            X.append(now)
        else:
            flag = 0
    else:
        now = c
        flag = 1

Q = int(input())
for _ in range(Q):
    q, x = map(int, input().split())
    if q == 1:
        print(bisect_right(X, x))
    else:
        print(Y[x - 1])
0