結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-29 11:55:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,173 ms / 3,000 ms |
| コード長 | 923 bytes |
| コンパイル時間 | 446 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 126,784 KB |
| 最終ジャッジ日時 | 2024-12-28 09:46:20 |
| 合計ジャッジ時間 | 34,637 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
import bisect
N = int(input())
needLV = [-1 for i in range(0,N+1)]
needLV[1] = 0
data = {}
LV = [0,0]
for i in range(1,N+1):
data[i] = []
for i in range(N-1):
L,A = map(int,input().split())
data[A].append(i+2)
LV.append(L)
#print(data)
nex = [1]
visited = [0 for i in range(0,N+1)]
while nex != []:
nex2 = []
for i in nex:
visited[i] = 1
for j in data[i]:
if visited[j] == 0:
needLV[j] = max(LV[i],LV[j],needLV[i])
nex2.append(j)
nex = nex2.copy()
Q = int(input())
bisect_lis = []
for i in range(0,len(needLV)):
if needLV[i] == -1:
bisect_lis.append(10**10)
else:
bisect_lis.append(needLV[i])
bisect_lis = sorted(bisect_lis)
for i in range(Q):
num,sub = map(int,input().split())
if num == 1:
print(bisect.bisect_right(bisect_lis,sub))
else:
print(needLV[sub])