結果

問題 No.2325 Skill Tree
ユーザー titiatitia
提出日時 2023-06-02 03:44:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,881 ms / 3,000 ms
コード長 689 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 93,132 KB
最終ジャッジ日時 2023-08-28 02:17:28
合計ジャッジ時間 75,653 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,044 KB
testcase_01 AC 17 ms
8,112 KB
testcase_02 AC 17 ms
8,148 KB
testcase_03 AC 17 ms
8,056 KB
testcase_04 AC 18 ms
8,108 KB
testcase_05 AC 17 ms
8,168 KB
testcase_06 AC 17 ms
8,116 KB
testcase_07 AC 950 ms
18,832 KB
testcase_08 AC 782 ms
41,016 KB
testcase_09 AC 1,075 ms
30,892 KB
testcase_10 AC 986 ms
63,632 KB
testcase_11 AC 1,132 ms
47,476 KB
testcase_12 AC 2,131 ms
87,636 KB
testcase_13 AC 2,114 ms
87,640 KB
testcase_14 AC 2,116 ms
87,704 KB
testcase_15 AC 2,146 ms
87,744 KB
testcase_16 AC 2,144 ms
87,644 KB
testcase_17 AC 2,067 ms
87,776 KB
testcase_18 AC 2,064 ms
87,636 KB
testcase_19 AC 2,067 ms
87,772 KB
testcase_20 AC 2,141 ms
87,636 KB
testcase_21 AC 2,093 ms
87,712 KB
testcase_22 AC 2,158 ms
87,760 KB
testcase_23 AC 2,213 ms
87,728 KB
testcase_24 AC 2,170 ms
87,692 KB
testcase_25 AC 2,194 ms
87,632 KB
testcase_26 AC 2,175 ms
87,756 KB
testcase_27 AC 2,817 ms
93,048 KB
testcase_28 AC 2,826 ms
93,132 KB
testcase_29 AC 2,797 ms
92,768 KB
testcase_30 AC 2,795 ms
93,012 KB
testcase_31 AC 2,824 ms
93,076 KB
testcase_32 AC 2,669 ms
92,940 KB
testcase_33 AC 2,713 ms
92,948 KB
testcase_34 AC 2,738 ms
93,072 KB
testcase_35 AC 2,860 ms
93,072 KB
testcase_36 AC 2,881 ms
93,036 KB
testcase_37 AC 2,843 ms
93,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
from bisect import bisect

N=int(input())
T=[list(map(int,input().split())) for i in range(N-1)]

E=[[] for i in range(N)]

for i in range(N-1):
    l,a=T[i]
    a-=1

    E[a].append((i+1,l))

LEVEL=[1<<60]*N
LEVEL[0]=0

Q=[(0,0)]

while Q:
    x,level=heappop(Q)

    for to,lev in E[x]:
        if LEVEL[to]>max(level,lev):
            LEVEL[to]=max(level,lev)
            heappush(Q,(to,LEVEL[to]))
            
SL=sorted(LEVEL)


for i in range(N):
    if LEVEL[i]==1<<60:
        LEVEL[i]=-1


Q=int(input())

for tests in range(Q):
    com,x=map(int,input().split())

    if com==1:
        print(bisect(SL,x))
    else:
        print(LEVEL[x-1])
0