結果

問題 No.2316 Freight Train
ユーザー KudeKude
提出日時 2023-05-26 21:27:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 631 ms / 2,000 ms
コード長 338 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 107,368 KB
最終ジャッジ日時 2023-08-26 10:13:59
合計ジャッジ時間 17,096 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,336 KB
testcase_01 AC 73 ms
71,176 KB
testcase_02 AC 71 ms
71,308 KB
testcase_03 AC 623 ms
106,960 KB
testcase_04 AC 389 ms
90,476 KB
testcase_05 AC 310 ms
90,336 KB
testcase_06 AC 185 ms
78,420 KB
testcase_07 AC 556 ms
82,548 KB
testcase_08 AC 406 ms
107,136 KB
testcase_09 AC 488 ms
94,644 KB
testcase_10 AC 526 ms
90,672 KB
testcase_11 AC 466 ms
103,640 KB
testcase_12 AC 551 ms
100,380 KB
testcase_13 AC 624 ms
107,096 KB
testcase_14 AC 630 ms
107,256 KB
testcase_15 AC 630 ms
107,252 KB
testcase_16 AC 622 ms
107,260 KB
testcase_17 AC 631 ms
107,368 KB
testcase_18 AC 621 ms
107,260 KB
testcase_19 AC 631 ms
107,200 KB
testcase_20 AC 626 ms
107,208 KB
testcase_21 AC 624 ms
107,288 KB
testcase_22 AC 627 ms
107,332 KB
testcase_23 AC 546 ms
107,128 KB
testcase_24 AC 591 ms
107,140 KB
testcase_25 AC 580 ms
105,356 KB
testcase_26 AC 539 ms
105,364 KB
testcase_27 AC 492 ms
77,048 KB
testcase_28 AC 73 ms
71,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())
p = [pi - 1 if pi > 0 else i for i, pi in enumerate(map(int, input().split()))]
for i in range(n):
    j = i
    while p[j] != j:
        j = p[j]
    while i != j:
        p[i] = j
        i = p[i]
for _ in range(q):
    a, b = map(int, input().split())
    print('Yes' if p[a - 1] == p[b - 1] else 'No')
0