結果

問題 No.2316 Freight Train
ユーザー Ekiben542Ekiben542
提出日時 2023-05-26 21:25:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 430 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 31,484 KB
最終ジャッジ日時 2023-08-26 10:02:53
合計ジャッジ時間 26,584 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,868 KB
testcase_01 AC 13 ms
7,772 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,102 ms
31,016 KB
testcase_24 AC 1,149 ms
31,204 KB
testcase_25 AC 1,209 ms
25,028 KB
testcase_26 AC 1,112 ms
24,920 KB
testcase_27 AC 974 ms
7,708 KB
testcase_28 AC 14 ms
7,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


train_line = [0] * N

line_num = 1
for i in range(N):
    if P[i] == -1:
        train_line[i] = line_num
        line_num += 1

for i in range(N):
    if P[i] != -1:
        train_line[i] = train_line[P[i]-1]
for _ in range(Q):
    A, B = map(int, input().split())
    if train_line[A-1] == train_line[B-1]:
        print("Yes")
    else:
        print("No")
0