結果

問題 No.2325 Skill Tree
ユーザー rlangevin
提出日時 2023-05-31 12:18:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 659 ms / 3,000 ms
コード長 707 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 112,284 KB
最終ジャッジ日時 2024-12-28 13:40:07
合計ジャッジ時間 19,477 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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