結果
問題 | No.2325 Skill Tree |
ユーザー |
![]() |
提出日時 | 2023-06-05 21:41:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 980 ms / 3,000 ms |
コード長 | 679 bytes |
コンパイル時間 | 517 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 100,480 KB |
最終ジャッジ日時 | 2024-12-29 06:26:00 |
合計ジャッジ時間 | 29,075 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
N = int(input())S = [[] for _ in range(N + 1)] # S[i]:= iを覚えていると思えられる技のリストL = [0] * (N + 1) # L[i]:= 技iを覚えるのに必要なレベルL[1] = 1L1 = [-1] * (N + 1)L1[1] = 1for i in range(2, N + 1):l, s = map(int, input().split())S[s].append(i)L[i] = lq = [1]while q:x = q.pop(-1)for y in S[x]:L1[y] = max(L1[x], L[y])q.append(y)L2 = L1[:]L2.sort()from bisect import *x = bisect_left(L2, 0)L2 = L2[x:]# print(L)# print(L2)Q = int(input())for _ in range(Q):t, x = map(int, input().split())if t == 1:print(bisect_right(L2, x))else:print(L1[x])