結果
| 問題 | No.2325 Skill Tree |
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2023-05-28 14:22:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,095 bytes |
| コンパイル時間 | 1,007 ms |
| コンパイル使用メモリ | 81,808 KB |
| 実行使用メモリ | 148,116 KB |
| 最終ジャッジ日時 | 2024-12-27 00:57:15 |
| 合計ジャッジ時間 | 69,139 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 TLE * 3 |
ソースコード
import bisect
N=int(input())
lis=[]
for i in range(N-1):
L,A=map(int,input().split())
lis.append([L,A,i+2])
lis.sort()
use=[False for _ in range(N+2)]
sets=[set() for _ in range(N+2)]
use[1]=True
nums=[-1 for _ in range(N+2)]
count=[0 for _ in range(N+2)]
from collections import deque
for l,a,ind in lis:
if use[a]:
i=ind-2
use[ind]=True
nums[ind]=l
dq=deque()
dq.append(ind)
while len(dq)!=0:
p=dq.popleft()
for s in sets[p]:
use[s]=True
nums[s]=l
dq.append(s)
else:
sets[a].add(ind)
import bisect
point=[0 for _ in range(len(lis)+1)]
for i in range(2,N+1):
if nums[i]!=-1:
point[bisect.bisect_left(lis,[nums[i]])]+=1
for i in range(1,len(point)):
point[i]+=point[i-1]
point.append(0)
for i in range(len(point)):
point[i]+=1
Q=int(input())
for _ in range(Q):
q=list(map(int,input().split()))
if q[0]==2:
print(nums[q[1]])
if q[0]==1:
print(point[bisect.bisect_right(lis,[q[1],10**9])-1])
pass
nikoro256