結果

問題 No.1814 Uribo Road (Easy)
ユーザー ShirotsumeShirotsume
提出日時 2021-11-04 22:05:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 79,632 KB
最終ジャッジ日時 2024-05-01 17:28:02
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,148 KB
testcase_01 AC 45 ms
61,732 KB
testcase_02 AC 37 ms
52,684 KB
testcase_03 AC 35 ms
53,132 KB
testcase_04 AC 36 ms
52,820 KB
testcase_05 AC 37 ms
52,268 KB
testcase_06 AC 42 ms
61,944 KB
testcase_07 AC 36 ms
53,060 KB
testcase_08 AC 36 ms
52,604 KB
testcase_09 AC 60 ms
67,692 KB
testcase_10 AC 57 ms
65,604 KB
testcase_11 AC 89 ms
77,000 KB
testcase_12 AC 112 ms
77,464 KB
testcase_13 AC 92 ms
76,816 KB
testcase_14 AC 112 ms
76,936 KB
testcase_15 AC 109 ms
68,608 KB
testcase_16 AC 146 ms
70,896 KB
testcase_17 AC 151 ms
70,940 KB
testcase_18 AC 151 ms
71,660 KB
testcase_19 AC 150 ms
72,464 KB
testcase_20 AC 175 ms
77,492 KB
testcase_21 AC 185 ms
77,116 KB
testcase_22 AC 241 ms
78,216 KB
testcase_23 AC 251 ms
77,428 KB
testcase_24 AC 202 ms
79,436 KB
testcase_25 AC 246 ms
79,452 KB
testcase_26 AC 194 ms
78,856 KB
testcase_27 AC 201 ms
78,960 KB
testcase_28 AC 201 ms
79,240 KB
testcase_29 AC 261 ms
79,324 KB
testcase_30 AC 197 ms
79,476 KB
testcase_31 AC 192 ms
79,224 KB
testcase_32 AC 102 ms
76,980 KB
testcase_33 AC 62 ms
68,208 KB
testcase_34 AC 51 ms
63,540 KB
testcase_35 AC 105 ms
76,868 KB
testcase_36 AC 77 ms
73,680 KB
testcase_37 AC 128 ms
77,384 KB
testcase_38 AC 143 ms
77,652 KB
testcase_39 AC 94 ms
76,684 KB
testcase_40 AC 120 ms
77,764 KB
testcase_41 AC 258 ms
79,632 KB
testcase_42 AC 163 ms
77,792 KB
testcase_43 AC 97 ms
77,200 KB
testcase_44 AC 112 ms
76,992 KB
testcase_45 AC 92 ms
76,704 KB
testcase_46 AC 201 ms
79,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 18

N, M, K = map(int,input().split())

assert (1 <= N <= 200 and K <= 5 and 1 <= K <= M <= N * (N - 1) // 2)

dist = [[0 if i == j else INF for i in range(N)] for j in range(N)]

R = list(map(int,input().split()))
points = []
nes_cost = 0
check_set = set()
for i in range(M):
    A, B, C = map(int,input().split())
    assert(1 <= C <= 10 ** 4 and 1 <= A <= N and 1 <= B <= N and A != B)
    assert((A, B) not in check_set and (B, A) not in check_set)
    if i + 1 in R:
        nes_cost += C
        points.append((A - 1, B - 1))


    check_set.add((A, B))
    dist[A - 1][B - 1] = C
    dist[B - 1][A - 1] = C

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
for i in range(N):
    for j in range(N):
        assert(dist[i][j] < INF)


import itertools
ans = INF
for v in itertools.permutations(points):
    for i in range(2 ** K):
        now = 0
        now_cost = nes_cost
        for j in range(K):
            x, y = v[j]
            if 1 & (i >> j):
                now_cost += dist[now][x]
                now = y
            else:
                now_cost += dist[now][y]
                now = x
        now_cost += dist[now][N - 1]
        ans = min(ans, now_cost)
print(ans)


0