結果

問題 No.2325 Skill Tree
ユーザー cozy_saunacozy_sauna
提出日時 2023-05-28 13:52:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 602 ms / 3,000 ms
コード長 2,729 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 126,336 KB
最終ジャッジ日時 2024-12-26 22:07:23
合計ジャッジ時間 21,496 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
89,216 KB
testcase_01 AC 153 ms
89,344 KB
testcase_02 AC 157 ms
88,832 KB
testcase_03 AC 153 ms
89,088 KB
testcase_04 AC 150 ms
88,832 KB
testcase_05 AC 145 ms
88,832 KB
testcase_06 AC 148 ms
88,960 KB
testcase_07 AC 287 ms
93,440 KB
testcase_08 AC 284 ms
99,200 KB
testcase_09 AC 313 ms
97,024 KB
testcase_10 AC 335 ms
106,112 KB
testcase_11 AC 337 ms
101,504 KB
testcase_12 AC 470 ms
114,176 KB
testcase_13 AC 477 ms
114,304 KB
testcase_14 AC 470 ms
114,432 KB
testcase_15 AC 481 ms
114,304 KB
testcase_16 AC 466 ms
114,304 KB
testcase_17 AC 456 ms
112,896 KB
testcase_18 AC 432 ms
112,768 KB
testcase_19 AC 437 ms
112,640 KB
testcase_20 AC 434 ms
112,896 KB
testcase_21 AC 485 ms
112,640 KB
testcase_22 AC 444 ms
116,224 KB
testcase_23 AC 464 ms
116,352 KB
testcase_24 AC 470 ms
116,352 KB
testcase_25 AC 439 ms
113,920 KB
testcase_26 AC 456 ms
116,352 KB
testcase_27 AC 602 ms
126,080 KB
testcase_28 AC 543 ms
125,824 KB
testcase_29 AC 583 ms
125,696 KB
testcase_30 AC 567 ms
125,952 KB
testcase_31 AC 557 ms
126,208 KB
testcase_32 AC 559 ms
124,928 KB
testcase_33 AC 501 ms
126,080 KB
testcase_34 AC 518 ms
125,824 KB
testcase_35 AC 601 ms
125,824 KB
testcase_36 AC 554 ms
125,440 KB
testcase_37 AC 599 ms
126,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit, stdin
from collections import defaultdict, deque, Counter
from itertools import permutations, combinations, product
from functools import lru_cache
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop
from copy import copy, deepcopy
from decimal import Decimal
from random import random, randrange

# from pypyjit import set_param
# set_param('max_unroll_recursion=-1')

setrecursionlimit(1 << 20)
readline = stdin.readline
INF = 10 ** 18
MOD = 998244353
# MOD = 1000000007
ALP = 26
''' Input '''
def I(): return int(readline())
def ST(): return readline()[:-1]
def LI(): return list(map(int, readline().split()))
def LII(): return list(map(lambda x: int(x) - 1, readline().split()))
def LF(x, func): return [func() for _ in [0] * x]
def SPI(): return map(int, readline().split())
def SPII(): return map(lambda x: int(x) - 1, readline().split())
def FIE(x): return [readline()[:-1] for _ in [0] * x]

''' Array '''
def cmin(dp, i, x):
    if x < dp[i]: dp[i] = x
def cmax(dp, i, x):
    if x > dp[i]: dp[i] = x

''' Alphabet '''
def alp_a_to_i(s): return ord(s) - ord('a')
def alp_A_to_i(s): return ord(s) - ord('A')
def alp_i_to_a(i): return chr(ord('a') + i)
def alp_i_to_A(i): return chr(ord('A') + i)

''' Other'''
def nynx(y, x, H, W): return [(y + dy, x + dx) for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)] if 0 <= y + dy < H and 0 <= x + dx < W]
def gen(x, *args):
    if len(args) == 1: return [x] * args[0]
    if len(args) == 2: return [[x] * args[1] for _ in [0] * args[0]]
    if len(args) == 3: return [[[x] * args[2] for _ in [0] * args[1]] for _ in [0] * args[0]]
    if len(args) == 4: return [[[[x] * args[3] for _ in [0] * args[2]] for _ in [0] * args[1]] for _ in [0] * args[0]]

''' Output '''
def pprint(E): 
    print()
    for e in E: print(e)
def Yes(): print("Yes")
def No(): print("No")
def YES(): print("YES")
def NO(): print("NO")
def yn(x): print("Yes" if x else "No")
def YN(x): print("YES" if x else "NO")
###############################################################################################

N = I()
node = [[] for _ in range(N)]
LA = []
for i in range(N - 1):
    i += 1
    l, a = SPI()
    a -= 1
    node[a].append((i, l))

COST = []
dist = gen(INF, N)
que = deque([(0, 0)])
while que:
    v, c = que.popleft()
    if dist[v] != INF: continue
    COST.append(c)
    dist[v] = c
    for nx, nx_c in node[v]:
        que.appendleft((nx, max(c, nx_c)))


COST.sort()
# print(COST)
Q = I()
for _ in range(Q):
    c, *A = SPI()
    if c == 1:
        x = A[0]
        ans = bisect_right(COST, x)
        print(ans)
    if c == 2:
        y = A[0] - 1
        ans = dist[y]
        if ans == INF: ans = -1
        print(ans)
0