結果

問題 No.2325 Skill Tree
ユーザー pありpあり
提出日時 2023-05-28 14:21:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 991 ms / 3,000 ms
コード長 663 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 111,952 KB
最終ジャッジ日時 2023-08-27 09:35:00
合計ジャッジ時間 30,303 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,692 KB
testcase_01 AC 95 ms
71,420 KB
testcase_02 AC 100 ms
71,540 KB
testcase_03 AC 96 ms
71,672 KB
testcase_04 AC 95 ms
71,552 KB
testcase_05 AC 97 ms
71,452 KB
testcase_06 AC 96 ms
71,672 KB
testcase_07 AC 484 ms
83,284 KB
testcase_08 AC 380 ms
90,964 KB
testcase_09 AC 515 ms
87,228 KB
testcase_10 AC 449 ms
100,800 KB
testcase_11 AC 517 ms
94,280 KB
testcase_12 AC 823 ms
111,188 KB
testcase_13 AC 826 ms
111,148 KB
testcase_14 AC 812 ms
111,500 KB
testcase_15 AC 839 ms
111,596 KB
testcase_16 AC 828 ms
111,476 KB
testcase_17 AC 807 ms
111,488 KB
testcase_18 AC 802 ms
111,248 KB
testcase_19 AC 808 ms
111,464 KB
testcase_20 AC 817 ms
111,384 KB
testcase_21 AC 792 ms
111,500 KB
testcase_22 AC 831 ms
111,248 KB
testcase_23 AC 842 ms
111,156 KB
testcase_24 AC 831 ms
111,308 KB
testcase_25 AC 832 ms
111,260 KB
testcase_26 AC 827 ms
111,136 KB
testcase_27 AC 985 ms
110,732 KB
testcase_28 AC 957 ms
110,032 KB
testcase_29 AC 991 ms
109,408 KB
testcase_30 AC 964 ms
111,364 KB
testcase_31 AC 962 ms
111,952 KB
testcase_32 AC 904 ms
109,756 KB
testcase_33 AC 907 ms
110,144 KB
testcase_34 AC 925 ms
109,844 KB
testcase_35 AC 967 ms
111,192 KB
testcase_36 AC 941 ms
110,752 KB
testcase_37 AC 965 ms
111,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect

n = int(input())

la = [(0, 0)]

g = [[] for _ in range(n)]

for i in range(1, n):
  l,a = map(int, input().split())
  a-=1
  la.append((l,a))
  
  g[a].append(i)
  
M = 10**18
ans = [M for _ in range(n)]

d = deque([(0, 0)])

while(d):
  now, l = d.pop()
  
  l = max(la[now][0], l)
  
  ans[now] = l
  
  for v in g[now]:
    d.append((v,l))
    

ans2 = [i for i in ans]

ans2.sort() 
  
  
  
  
q = int(input())

for _ in range(q):
  a,x = map(int, input().split())
  
  if(a==1):
    print(bisect.bisect(ans2,x))
    
  else:
    x-=1
    if(ans[x]==M):
      print(-1)
    else:
      print(ans[x])
      
    
0