結果

問題 No.2325 Skill Tree
ユーザー AyunaAyuna
提出日時 2023-05-28 14:48:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 54,812 KB
最終ジャッジ日時 2023-08-27 10:40:34
合計ジャッジ時間 65,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,764 KB
testcase_01 AC 18 ms
8,748 KB
testcase_02 AC 19 ms
8,712 KB
testcase_03 AC 20 ms
8,604 KB
testcase_04 AC 20 ms
8,716 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 682 ms
26,324 KB
testcase_09 WA -
testcase_10 AC 928 ms
38,200 KB
testcase_11 AC 1,126 ms
29,564 KB
testcase_12 AC 2,014 ms
51,252 KB
testcase_13 AC 2,030 ms
51,232 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2,041 ms
51,292 KB
testcase_17 AC 2,004 ms
51,252 KB
testcase_18 AC 2,008 ms
51,128 KB
testcase_19 AC 2,038 ms
51,116 KB
testcase_20 AC 2,096 ms
51,148 KB
testcase_21 AC 2,005 ms
51,252 KB
testcase_22 AC 2,054 ms
51,120 KB
testcase_23 WA -
testcase_24 AC 2,054 ms
51,244 KB
testcase_25 AC 2,020 ms
51,304 KB
testcase_26 AC 2,058 ms
51,180 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2,395 ms
54,208 KB
testcase_33 AC 2,402 ms
54,100 KB
testcase_34 AC 2,401 ms
54,108 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#技の種類数は累積和
from collections import defaultdict
from collections import deque
from bisect import bisect
n = int(input())
L = [-1 for _ in range(n)]
L[0] = 1
tree = [[] for _ in range(n)]
for i in range(n - 1):
    l, a = map(int, input().split())
    tree[i + 1].append(a - 1)
    tree[a - 1].append(i + 1)
    L[i + 1] = l
q = deque([(0, 1)])
dic = defaultdict(int)
seen = [False for _ in range(n)]
seen[0] = True
while q:
    now, lev = q.popleft()
    if L[now] < lev:
        L[now] = lev
    for next in tree[now]:
        if seen[next]: continue
        q.append((next, L[now]))
        seen[next] = True

for i in range(n):
    if not seen[i]:
        L[i] = -1
for i in L:
    if i != -1:
        dic[i] += 1

lis1 = list(dic.keys())
lis2 = [0] + [dic[i] for i in lis1]
for i in range(len(lis2) - 1):
    lis2[i + 1] += lis2[i]
q = int(input())
for i in range(q):
    num, x = map(int, input().split())
    if num == 1:
        wh = bisect(lis1, x)
        print(lis2[wh])
    else:
        print(L[x - 1])
0