結果

問題 No.2316 Freight Train
ユーザー 👑 p-adicp-adic
提出日時 2023-05-28 08:10:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,588 ms / 2,000 ms
コード長 271 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 31,528 KB
最終ジャッジ日時 2023-09-14 08:44:45
合計ジャッジ時間 37,266 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,884 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,848 KB
testcase_03 AC 1,523 ms
31,528 KB
testcase_04 AC 820 ms
19,300 KB
testcase_05 AC 596 ms
19,320 KB
testcase_06 AC 192 ms
9,952 KB
testcase_07 AC 1,250 ms
13,712 KB
testcase_08 AC 923 ms
31,176 KB
testcase_09 AC 1,156 ms
22,976 KB
testcase_10 AC 1,218 ms
20,696 KB
testcase_11 AC 1,088 ms
29,224 KB
testcase_12 AC 1,308 ms
27,092 KB
testcase_13 AC 1,572 ms
31,076 KB
testcase_14 AC 1,569 ms
31,080 KB
testcase_15 AC 1,588 ms
31,040 KB
testcase_16 AC 1,556 ms
31,080 KB
testcase_17 AC 1,557 ms
31,232 KB
testcase_18 AC 1,549 ms
31,244 KB
testcase_19 AC 1,579 ms
31,260 KB
testcase_20 AC 1,570 ms
31,156 KB
testcase_21 AC 1,560 ms
31,180 KB
testcase_22 AC 1,569 ms
31,216 KB
testcase_23 AC 1,319 ms
31,180 KB
testcase_24 AC 1,402 ms
31,196 KB
testcase_25 AC 1,343 ms
25,072 KB
testcase_26 AC 1,227 ms
25,128 KB
testcase_27 AC 1,116 ms
7,884 KB
testcase_28 AC 17 ms
7,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

R=range
def J():
	return map(int,input().split())
N,Q=J()
P=list(J())
p=[n for n in R(N+1)]
def r(i):
	m=p[i]
	while i!=m:
		p[i]=i=p[m]
		m=p[i]
	return i
for i in R(N):
	if P[i]>0:
		A,B=r(i+1),r(P[i])
		p[A]=B
for q in R(Q):
	A,B=J()
	print("Yes"if r(A)==r(B)else"No")
0