結果

問題 No.2325 Skill Tree
ユーザー dango
提出日時 2023-06-13 21:24:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 986 ms / 3,000 ms
コード長 540 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 105,296 KB
最終ジャッジ日時 2024-06-22 07:41:23
合計ジャッジ時間 32,057 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect, collections
N = int(input())
E = [[] for _ in range(N)]
TEMP = [1]
for i in range(1, N):
  Li, Ai = map(int, input().split())
  TEMP.append(Li)
  E[Ai - 1].append(i)
INFINITY = 1 << 30
L = [INFINITY] * N
L[0] = 1
D = collections.deque([0])
while D:
  U = D.popleft()
  for V in E[U]:
    L[V] = max(TEMP[V], L[U])
    D.append(V)
SL = sorted(L)
for _ in range(int(input())):
  T, X = list(map(int, input().split()))
  if T == 1:
    print(bisect.bisect_right(SL, X))
  else:
    print(L[X - 1] if L[X - 1] < INFINITY else -1)
0