結果

問題 No.2325 Skill Tree
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-07-24 03:21:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 356,400 KB
最終ジャッジ日時 2023-10-25 21:37:24
合計ジャッジ時間 33,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,700 KB
testcase_01 AC 47 ms
58,400 KB
testcase_02 AC 45 ms
55,700 KB
testcase_03 AC 46 ms
58,400 KB
testcase_04 AC 46 ms
55,700 KB
testcase_05 AC 45 ms
55,700 KB
testcase_06 AC 45 ms
55,700 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 941 ms
353,300 KB
testcase_17 AC 893 ms
352,664 KB
testcase_18 AC 821 ms
353,632 KB
testcase_19 AC 766 ms
353,640 KB
testcase_20 WA -
testcase_21 AC 808 ms
353,644 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 860 ms
356,284 KB
testcase_26 WA -
testcase_27 AC 427 ms
109,196 KB
testcase_28 AC 422 ms
109,172 KB
testcase_29 AC 395 ms
108,580 KB
testcase_30 AC 403 ms
108,968 KB
testcase_31 AC 402 ms
109,176 KB
testcase_32 AC 354 ms
109,128 KB
testcase_33 AC 373 ms
108,928 KB
testcase_34 AC 371 ms
109,128 KB
testcase_35 AC 424 ms
109,172 KB
testcase_36 AC 408 ms
109,176 KB
testcase_37 AC 420 ms
109,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
sys.setrecursionlimit(3*10**5)
input = sys.stdin.readline

N = int(input())
e = [[] for _ in range(N)]
INF = (1<<60)
val = [INF]*N
val[0] = 0
for i in range(N-1):
    l,a = map(int,input().split())
    a -= 1
    e[i+1].append((a,l))
def cle(a,D):
    
    y = len(D)-1
    x = 0
    if D[x]>a:
        return 0
        
    if D[y]<=a:
        return y+1
    
    while y-x>1:
        mid = (y+x)//2
        if D[mid]<=a:
            x = mid
        else:
            y = mid
    return y
cnt = 0
def f(x):
    global cnt
    if val[x]!=INF:
        return val[x]
    tmp = 0
    cnt += 1
    if cnt >= N+1000:
        val[x]=INF-1
        return val[x]
    for ix,iw in e[x]:
        tmp = max(tmp,f(ix),iw)
    val[x] = tmp
    return val[x]
    


Q = int(input())
for i in range(N):
    f(i)
X = val[:]
X.sort()
for _ in range(Q):
    query = list(map(int,input().split()))
    if query[0]==1:
        x = query[1]
        print(cle(x,X))
    else:
        y = query[1]
        if val[y-1]==INF-1:
            print(-1)
        else:
            print(val[y-1])
0