結果

問題 No.2325 Skill Tree
ユーザー masa_aamasa_aa
提出日時 2023-05-28 14:17:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 977 ms / 3,000 ms
コード長 1,302 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 152,904 KB
最終ジャッジ日時 2023-08-27 09:26:57
合計ジャッジ時間 29,258 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,612 KB
testcase_01 AC 94 ms
71,588 KB
testcase_02 AC 95 ms
71,840 KB
testcase_03 AC 95 ms
71,516 KB
testcase_04 AC 95 ms
71,556 KB
testcase_05 AC 95 ms
71,584 KB
testcase_06 AC 96 ms
71,760 KB
testcase_07 AC 253 ms
89,148 KB
testcase_08 AC 346 ms
99,688 KB
testcase_09 AC 315 ms
96,168 KB
testcase_10 AC 474 ms
116,836 KB
testcase_11 AC 399 ms
104,864 KB
testcase_12 AC 762 ms
146,396 KB
testcase_13 AC 803 ms
146,204 KB
testcase_14 AC 820 ms
142,888 KB
testcase_15 AC 753 ms
145,860 KB
testcase_16 AC 736 ms
145,920 KB
testcase_17 AC 720 ms
145,876 KB
testcase_18 AC 728 ms
146,032 KB
testcase_19 AC 727 ms
145,776 KB
testcase_20 AC 753 ms
145,880 KB
testcase_21 AC 713 ms
146,240 KB
testcase_22 AC 752 ms
146,096 KB
testcase_23 AC 775 ms
143,808 KB
testcase_24 AC 741 ms
146,308 KB
testcase_25 AC 747 ms
145,568 KB
testcase_26 AC 746 ms
145,852 KB
testcase_27 AC 906 ms
152,904 KB
testcase_28 AC 977 ms
151,152 KB
testcase_29 AC 950 ms
150,572 KB
testcase_30 AC 916 ms
151,708 KB
testcase_31 AC 920 ms
152,864 KB
testcase_32 AC 898 ms
150,088 KB
testcase_33 AC 873 ms
151,824 KB
testcase_34 AC 871 ms
151,876 KB
testcase_35 AC 919 ms
150,884 KB
testcase_36 AC 975 ms
149,864 KB
testcase_37 AC 977 ms
150,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict
from bisect import bisect_left, bisect_right
# bisect_left(a, x): a[i] >= xとなるような最小のi.
# 昇順ソートされたリストaに昇順を崩さずxを挿入できる位置s(0-index)を返す.
# a = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
# s = bisect_left(a,4), s = 2


n = int(input())
la = [list(map(int, input().split())) + [i + 1] for i in range(n - 1)]
for v in la:
    v[1] -= 1

la.sort(key=lambda x: x[0])
d = defaultdict(int)
d[0] = 1

stk = defaultdict(list)
check = [-1] * n
check[0] = 1
for level, a, idx in la:
    if check[a] != -1:
        check[idx] = level
        d[level] += 1
        que = [idx]
        while que:
            k = que.pop()
            for x in stk[k]:
                check[x] = level
                que.append(x)
                d[level] += 1
            stk[k] = []

    else:
        stk[a].append(idx)

d = list(d.items())
d.sort(key=lambda x: x[0])
for i in range(len(d) - 1):
    d[i + 1] = (d[i + 1][0], d[i][1] + d[i + 1][1])

q = int(input())
res = [0] * q
for i in range(q):
    query, x = map(int, input().split())
    if query == 1:
        k = bisect_left(d, (x, n + 10))
        res[i] = d[k - 1][1]
    else:
        res[i] = check[x - 1]

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