結果

問題 No.92 逃走経路
ユーザー けむけむけむけむ
提出日時 2021-08-29 11:18:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,575 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-05-01 21:40:23
合計ジャッジ時間 7,328 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
11,136 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 233 ms
11,008 KB
testcase_06 AC 80 ms
11,264 KB
testcase_07 AC 79 ms
11,136 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 123 ms
10,880 KB
testcase_10 AC 943 ms
11,008 KB
testcase_11 AC 1,087 ms
11,008 KB
testcase_12 AC 2,575 ms
11,008 KB
testcase_13 AC 64 ms
10,880 KB
testcase_14 AC 111 ms
10,880 KB
testcase_15 AC 149 ms
11,008 KB
testcase_16 AC 129 ms
11,008 KB
testcase_17 AC 155 ms
11,136 KB
testcase_18 AC 100 ms
11,136 KB
testcase_19 AC 86 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def tousou(N, M, K, abcs, ds):
    abs = []
    cs = []
    for i in range(M):
        abc = abcs[i]
        abs.append([abc[0], abc[1]])
        cs.append(abc[2])
    koho = []
    for j in range(M):
        if cs[j] == ds[0]:
            koho.append(abs[j][0])
            koho.append(abs[j][1])
    koho = list(set(koho))
    for k in range(1, K):
        d = ds[k]
        koho2 = []
        for l in range(M):
            if cs[l] == d:
                ab = abs[l]
                if ab[0] in koho:
                    koho2.append(ab[1])
                if ab[1] in koho:
                    koho2.append(ab[0])
        koho = list(set(koho2))
    ans1 = len(koho)
    koho = sorted(koho)
    map_koho = list(map(str, koho))
    ans2 = ' '.join(map_koho)
    return [ans1, ans2]

def main():
    N, M, K = map(int, input().split())
    abcs = [0 for x in range(M)]
    for i in  range(M):
        abcs[i] = list(map(int, input().split()))
    ds = list(map(int, input().split()))
    ans = tousou(N, M, K, abcs, ds)
    print(ans[0])
    print(ans[1])

if __name__ == '__main__':
    main()
0