結果
問題 | No.2325 Skill Tree |
ユーザー |
👑 ![]() |
提出日時 | 2023-05-28 15:28:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 457 ms / 3,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 119,596 KB |
最終ジャッジ日時 | 2024-12-27 06:54:49 |
合計ジャッジ時間 | 14,996 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
from sys import stdinimport bisectfrom collections import dequeN = int(stdin.readline())L = [0] + [float("inf")] * (N-1)lis = [ [] for i in range(N) ]for i in range(N-1):l,a = map(int,stdin.readline().split())a -= 1lis[a].append( (i+1,l) )q = deque([0])while q:v = q.popleft()for nex,cost in lis[v]:L[nex] = max(L[v] , cost)q.append(nex)L2 = [i for i in L]L2.sort()Q = int(stdin.readline())ANS = []for loop in range(Q):ty,x = map(int,stdin.readline().split())if ty == 1:idx = bisect.bisect_right(L2,x)ANS.append(idx)else:if L[x-1] == float("inf"):ANS.append(-1)else:ANS.append(L[x-1])print (*ANS,sep="\n")