結果

問題 No.2325 Skill Tree
ユーザー praticapratica
提出日時 2023-05-28 15:20:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,627 ms / 3,000 ms
コード長 774 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 124,080 KB
最終ジャッジ日時 2023-08-27 12:00:04
合計ジャッジ時間 36,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,796 KB
testcase_01 AC 79 ms
71,252 KB
testcase_02 AC 79 ms
71,176 KB
testcase_03 AC 79 ms
71,236 KB
testcase_04 AC 77 ms
70,916 KB
testcase_05 AC 75 ms
71,184 KB
testcase_06 AC 76 ms
71,268 KB
testcase_07 AC 469 ms
83,840 KB
testcase_08 AC 357 ms
95,184 KB
testcase_09 AC 520 ms
89,012 KB
testcase_10 AC 420 ms
107,572 KB
testcase_11 AC 524 ms
98,004 KB
testcase_12 AC 806 ms
121,668 KB
testcase_13 AC 821 ms
121,088 KB
testcase_14 AC 814 ms
121,492 KB
testcase_15 AC 838 ms
122,480 KB
testcase_16 AC 811 ms
121,656 KB
testcase_17 AC 785 ms
120,740 KB
testcase_18 AC 787 ms
121,068 KB
testcase_19 AC 774 ms
121,172 KB
testcase_20 AC 778 ms
120,804 KB
testcase_21 AC 787 ms
121,040 KB
testcase_22 AC 807 ms
122,272 KB
testcase_23 AC 807 ms
122,480 KB
testcase_24 AC 827 ms
122,568 KB
testcase_25 AC 805 ms
121,516 KB
testcase_26 AC 808 ms
122,416 KB
testcase_27 AC 1,588 ms
122,304 KB
testcase_28 AC 1,592 ms
123,216 KB
testcase_29 AC 1,586 ms
122,488 KB
testcase_30 AC 1,587 ms
123,440 KB
testcase_31 AC 1,591 ms
122,252 KB
testcase_32 AC 1,502 ms
122,444 KB
testcase_33 AC 1,530 ms
122,700 KB
testcase_34 AC 1,562 ms
124,080 KB
testcase_35 AC 1,560 ms
122,012 KB
testcase_36 AC 1,581 ms
122,408 KB
testcase_37 AC 1,627 ms
122,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import bisect

N = int(input())
skill = []
for i in range(N-1):
    L,A = map(int,input().split())
    skill.append([L,A])
#print(skill)

p = [[] for i in range(N)]
for i in range(N-1):
    p[skill[i][1]-1].append(i+1)
    
que = []
heapq.heapify(que)
heapq.heappush(que,[1,0])
seen = [-1]*N
seen[0] = 1
#print(que)

level = 0
while que:
    l, now = heapq.heappop(que)
    if level <= l:
        level = l
    seen[now] = level
    for next in p[now]:
        heapq.heappush(que,[skill[next-1][0],next])
    
    
levellist = sorted(seen)
cnt = seen.count(-1)

Q = int(input())
for q in range(Q):
    a = list(map(int,input().split()))
    #print(a)
    if a[0] == 1:
        print(bisect.bisect_right(levellist,a[1])-cnt)
    else:
        print(seen[a[1]-1])
0