結果

問題 No.2316 Freight Train
ユーザー Akijin_007Akijin_007
提出日時 2023-12-21 18:58:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,528 KB
最終ジャッジ日時 2023-12-21 18:58:12
合計ジャッジ時間 11,828 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,332 KB
testcase_01 AC 34 ms
53,332 KB
testcase_02 AC 35 ms
53,332 KB
testcase_03 AC 301 ms
108,244 KB
testcase_04 AC 197 ms
91,392 KB
testcase_05 AC 197 ms
90,908 KB
testcase_06 AC 105 ms
78,768 KB
testcase_07 AC 257 ms
97,876 KB
testcase_08 AC 218 ms
106,980 KB
testcase_09 AC 252 ms
96,160 KB
testcase_10 AC 285 ms
97,432 KB
testcase_11 AC 238 ms
103,832 KB
testcase_12 AC 267 ms
101,520 KB
testcase_13 AC 303 ms
108,528 KB
testcase_14 AC 328 ms
108,528 KB
testcase_15 AC 299 ms
108,516 KB
testcase_16 AC 297 ms
108,528 KB
testcase_17 AC 302 ms
108,528 KB
testcase_18 AC 316 ms
108,528 KB
testcase_19 AC 309 ms
108,528 KB
testcase_20 AC 305 ms
108,516 KB
testcase_21 AC 336 ms
108,528 KB
testcase_22 AC 301 ms
108,528 KB
testcase_23 AC 271 ms
108,528 KB
testcase_24 AC 293 ms
108,528 KB
testcase_25 AC 304 ms
106,800 KB
testcase_26 AC 269 ms
106,800 KB
testcase_27 AC 231 ms
96,732 KB
testcase_28 AC 35 ms
53,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
A = list(map(int, input().split()))

q = [0] * Q
for i in range(Q):
	q[i] = list(map(int, input().split()))
	
back = [-1] * N

for i in range(N):
	if A[i] != -1:
		back[A[i]-1] = i

p = [-1] * N
for i in range(N):
	if A[i] == -1:
		t = i
		while t != -1:
			p[t] = i
			t = back[t]

for i in range(Q):
	u, v = q[i]
	if p[u-1] == p[v-1]:
		print("Yes")
	else:
		print("No")

0