結果

問題 No.2316 Freight Train
ユーザー ryohei22ryohei22
提出日時 2023-06-02 15:52:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 668 ms / 2,000 ms
コード長 381 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 86,716 KB
実行使用メモリ 144,248 KB
最終ジャッジ日時 2023-08-28 02:22:57
合計ジャッジ時間 17,968 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,144 KB
testcase_01 AC 67 ms
71,260 KB
testcase_02 AC 65 ms
71,336 KB
testcase_03 AC 668 ms
127,792 KB
testcase_04 AC 395 ms
108,168 KB
testcase_05 AC 318 ms
108,196 KB
testcase_06 AC 173 ms
78,732 KB
testcase_07 AC 540 ms
89,340 KB
testcase_08 AC 423 ms
130,032 KB
testcase_09 AC 501 ms
117,808 KB
testcase_10 AC 523 ms
108,500 KB
testcase_11 AC 480 ms
119,816 KB
testcase_12 AC 554 ms
108,748 KB
testcase_13 AC 630 ms
130,212 KB
testcase_14 AC 640 ms
129,884 KB
testcase_15 AC 642 ms
130,764 KB
testcase_16 AC 643 ms
130,192 KB
testcase_17 AC 654 ms
131,800 KB
testcase_18 AC 648 ms
130,236 KB
testcase_19 AC 642 ms
130,052 KB
testcase_20 AC 638 ms
130,608 KB
testcase_21 AC 636 ms
130,340 KB
testcase_22 AC 639 ms
130,032 KB
testcase_23 AC 580 ms
144,216 KB
testcase_24 AC 622 ms
144,248 KB
testcase_25 AC 587 ms
114,728 KB
testcase_26 AC 560 ms
114,724 KB
testcase_27 AC 497 ms
78,084 KB
testcase_28 AC 69 ms
71,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
P = tuple(map(int, input().split()))

s = set(range(1, N+1))
for p in P:
	if p in s:
		s.remove(p)

g = [-1] * N
for i in s:
	p = i - 1
	lis = [p]
	while P[p] != -1:
		p = P[p] - 1
		lis.append(p)
	for j in lis:
		g[j] = p

for _ in range(Q):
	A, B = map(lambda x: int(x) - 1, input().split())
	if g[A] == g[B]:
		print('Yes')
	else:
		print('No')
0