結果

問題 No.2316 Freight Train
ユーザー KudeKude
提出日時 2023-05-26 21:27:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 615 ms / 2,000 ms
コード長 354 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 107,292 KB
最終ジャッジ日時 2023-08-26 10:16:22
合計ジャッジ時間 16,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,172 KB
testcase_01 AC 72 ms
71,332 KB
testcase_02 AC 71 ms
71,056 KB
testcase_03 AC 599 ms
107,192 KB
testcase_04 AC 374 ms
90,528 KB
testcase_05 AC 298 ms
90,348 KB
testcase_06 AC 178 ms
78,156 KB
testcase_07 AC 542 ms
81,984 KB
testcase_08 AC 382 ms
107,176 KB
testcase_09 AC 482 ms
94,724 KB
testcase_10 AC 510 ms
90,616 KB
testcase_11 AC 437 ms
103,864 KB
testcase_12 AC 522 ms
100,640 KB
testcase_13 AC 608 ms
107,256 KB
testcase_14 AC 608 ms
107,168 KB
testcase_15 AC 615 ms
107,280 KB
testcase_16 AC 602 ms
107,260 KB
testcase_17 AC 600 ms
107,140 KB
testcase_18 AC 606 ms
107,216 KB
testcase_19 AC 605 ms
107,264 KB
testcase_20 AC 604 ms
107,244 KB
testcase_21 AC 614 ms
107,208 KB
testcase_22 AC 594 ms
107,292 KB
testcase_23 AC 561 ms
107,128 KB
testcase_24 AC 579 ms
107,140 KB
testcase_25 AC 570 ms
105,340 KB
testcase_26 AC 551 ms
105,088 KB
testcase_27 AC 494 ms
77,252 KB
testcase_28 AC 71 ms
71,144 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:
        ni = p[i]
        p[i] = j
        i = ni
for _ in range(q):
    a, b = map(int, input().split())
    print('Yes' if p[a - 1] == p[b - 1] else 'No')
0