結果

問題 No.2325 Skill Tree
ユーザー konchakoncha
提出日時 2023-05-28 14:24:01
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,003 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 146,604 KB
最終ジャッジ日時 2023-08-27 09:41:51
合計ジャッジ時間 25,049 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,556 KB
testcase_01 AC 91 ms
71,636 KB
testcase_02 AC 98 ms
71,792 KB
testcase_03 AC 94 ms
71,792 KB
testcase_04 AC 92 ms
71,724 KB
testcase_05 RE -
testcase_06 AC 96 ms
71,312 KB
testcase_07 AC 317 ms
98,132 KB
testcase_08 AC 335 ms
102,988 KB
testcase_09 AC 400 ms
105,376 KB
testcase_10 AC 387 ms
114,996 KB
testcase_11 AC 394 ms
113,188 KB
testcase_12 AC 620 ms
144,364 KB
testcase_13 AC 607 ms
144,328 KB
testcase_14 AC 604 ms
144,356 KB
testcase_15 AC 628 ms
144,384 KB
testcase_16 AC 598 ms
144,104 KB
testcase_17 AC 573 ms
144,404 KB
testcase_18 AC 569 ms
144,100 KB
testcase_19 AC 576 ms
144,264 KB
testcase_20 AC 584 ms
144,116 KB
testcase_21 AC 579 ms
144,072 KB
testcase_22 AC 607 ms
144,412 KB
testcase_23 AC 607 ms
144,448 KB
testcase_24 AC 604 ms
144,376 KB
testcase_25 AC 589 ms
144,316 KB
testcase_26 AC 598 ms
144,308 KB
testcase_27 RE -
testcase_28 AC 838 ms
144,228 KB
testcase_29 AC 761 ms
142,932 KB
testcase_30 AC 780 ms
143,580 KB
testcase_31 RE -
testcase_32 AC 730 ms
144,308 KB
testcase_33 AC 733 ms
144,400 KB
testcase_34 AC 733 ms
144,364 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 759 ms
143,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
skills = [list(map(int, input().split())) for _ in range(N-1)]
Q = int(input())
querys = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for i, skill in enumerate(skills, start=1):
    graph[skill[1]-1].append(i)

skills = [(0, 0)] + skills

INF = 10**18
levels = [0] + [INF] * (N-1)
queue = deque([(0, 0)])
visited = [False] * (N+1)
visited[0] = False

while queue:
    now, prev = queue.popleft()
    if visited[now]:
        continue
    visited[now] = True
    levels[now] = max(skills[now][0], levels[prev])

    for u in graph[now]:
        queue.append((u, now))

s_levels = sorted(levels)

for q, l in querys:
    if q == 1:
        ok = 0
        ng = N+1
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if s_levels[mid] <= l:
                ok = mid
            else:
                ng = mid
        print(ok+1)
    if q == 2:
        print(levels[l-1] if levels[l-1] != INF else -1)
0