結果

問題 No.2325 Skill Tree
ユーザー 👑 p-adicp-adic
提出日時 2023-05-29 01:19:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 692 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 175,072 KB
最終ジャッジ日時 2023-08-27 18:33:15
合計ジャッジ時間 22,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,568 KB
testcase_01 AC 74 ms
71,408 KB
testcase_02 AC 74 ms
71,256 KB
testcase_03 AC 73 ms
71,336 KB
testcase_04 AC 74 ms
71,372 KB
testcase_05 AC 74 ms
71,420 KB
testcase_06 AC 75 ms
71,420 KB
testcase_07 AC 417 ms
109,360 KB
testcase_08 AC 396 ms
113,244 KB
testcase_09 AC 472 ms
121,444 KB
testcase_10 AC 496 ms
123,472 KB
testcase_11 AC 513 ms
130,056 KB
testcase_12 AC 819 ms
174,648 KB
testcase_13 AC 821 ms
174,300 KB
testcase_14 AC 817 ms
174,736 KB
testcase_15 AC 829 ms
170,284 KB
testcase_16 AC 781 ms
175,072 KB
testcase_17 AC 727 ms
156,624 KB
testcase_18 AC 773 ms
156,452 KB
testcase_19 AC 751 ms
156,456 KB
testcase_20 AC 767 ms
156,596 KB
testcase_21 AC 724 ms
156,424 KB
testcase_22 AC 783 ms
169,140 KB
testcase_23 AC 785 ms
171,500 KB
testcase_24 AC 771 ms
171,412 KB
testcase_25 AC 769 ms
165,820 KB
testcase_26 AC 781 ms
167,108 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

I,R=input,range
def S(n):
	return int(n)-1
def J():
	return map(S,I().split())
N=int(I())
p,w=[i for i in R(N)],[0]*N
def r(i):
	m=p[i]
	while i!=m:
		p[i]=i=p[m]
		m=p[i]
	return i
E,L=[set() for i in R(N)],[0]*N
for i in R(1,N):
	L[i],A=J()
	E[A].add(i)
	A,B=r(A),r(i)
	if w[B]<w[A]:A,B=B,A
	if w[A]==w[B]:w[B]+=1
	p[A]=B
n={0}
while len(n):
	i=n.pop()
	for e in E[i]:L[e]=max(L[e],L[i])
	n|=E[i]
Q=int(I())
t,y,X=[0]*Q,[0]*Q,set()
for i in R(Q):
	t[i],y[i]=J()
	X.add(y[i])
D,d,m,e={},0,[{0},set()],0
for x in sorted(X):
	n=m[e]
	while len(n):
		i=n.pop()
		if L[i]>x:m[1-e].add(i)
		else:d,n=d+1,n|E[i]
	D[x],e=d,1-e
for i in R(Q):print([-1,L[y[i]]+1][r(y[i])==r(0)] if t[i] else D[y[i]])
0