結果

問題 No.2325 Skill Tree
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-05-28 15:03:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 827 ms / 3,000 ms
コード長 881 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 155,492 KB
最終ジャッジ日時 2023-08-27 11:18:44
合計ジャッジ時間 22,818 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,392 KB
testcase_01 AC 73 ms
71,060 KB
testcase_02 AC 75 ms
71,160 KB
testcase_03 AC 75 ms
71,032 KB
testcase_04 AC 75 ms
71,100 KB
testcase_05 AC 72 ms
71,252 KB
testcase_06 AC 74 ms
71,260 KB
testcase_07 AC 312 ms
97,592 KB
testcase_08 AC 291 ms
101,428 KB
testcase_09 AC 343 ms
104,192 KB
testcase_10 AC 366 ms
114,296 KB
testcase_11 AC 371 ms
111,160 KB
testcase_12 AC 565 ms
142,472 KB
testcase_13 AC 589 ms
142,324 KB
testcase_14 AC 576 ms
142,120 KB
testcase_15 AC 578 ms
142,004 KB
testcase_16 AC 563 ms
142,888 KB
testcase_17 AC 534 ms
141,264 KB
testcase_18 AC 537 ms
141,256 KB
testcase_19 AC 543 ms
141,680 KB
testcase_20 AC 535 ms
141,488 KB
testcase_21 AC 539 ms
141,672 KB
testcase_22 AC 563 ms
143,600 KB
testcase_23 AC 565 ms
143,312 KB
testcase_24 AC 555 ms
143,564 KB
testcase_25 AC 545 ms
143,612 KB
testcase_26 AC 555 ms
143,336 KB
testcase_27 AC 683 ms
155,072 KB
testcase_28 AC 827 ms
154,776 KB
testcase_29 AC 767 ms
154,988 KB
testcase_30 AC 709 ms
155,440 KB
testcase_31 AC 727 ms
155,412 KB
testcase_32 AC 647 ms
154,964 KB
testcase_33 AC 645 ms
154,616 KB
testcase_34 AC 652 ms
154,856 KB
testcase_35 AC 718 ms
154,880 KB
testcase_36 AC 707 ms
155,492 KB
testcase_37 AC 699 ms
155,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
n = int(input())

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

q = int(input())
Q = [list(map(int,input().split())) for i in range(q)]

inf = 10**10
level = [inf]*n
level[0] = 1

nums = [0]*n
for i,(l,a) in enumerate(LA,1):
    level[i] = l
    e[a-1].append(i)
    nums[i] += 1


dist = [inf]*n
q = []
for i in range(n):
    if nums[i] == 0:
        q.append(i)
        dist[i] = level[i]

while q:
    now = q.pop()
    for nex in e[now]:
        nums[nex] -= 1
        if nums[nex] == 0:
            dist[nex] = max(dist[now],level[nex])
            q.append(nex)



techs = [inf]
for i in dist:
    if i != inf:
        techs.append(i)

techs.sort()

for t,x in Q:
    if t == 1:
        print(bisect.bisect_right(techs,x))
    else:
        ans = dist[x-1]
        if ans == inf:
            ans = -1
        print(ans)
0