結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-10-25 14:35:48 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 981 ms / 2,000 ms |
コード長 | 1,019 bytes |
コンパイル時間 | 107 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 13,668 KB |
最終ジャッジ日時 | 2024-11-21 22:55:20 |
合計ジャッジ時間 | 16,711 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 49 ms
10,752 KB |
testcase_02 | AC | 33 ms
10,752 KB |
testcase_03 | AC | 30 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 30 ms
10,624 KB |
testcase_06 | AC | 31 ms
10,752 KB |
testcase_07 | AC | 29 ms
10,752 KB |
testcase_08 | AC | 30 ms
10,752 KB |
testcase_09 | AC | 48 ms
10,752 KB |
testcase_10 | AC | 34 ms
10,752 KB |
testcase_11 | AC | 51 ms
11,008 KB |
testcase_12 | AC | 96 ms
11,136 KB |
testcase_13 | AC | 64 ms
11,008 KB |
testcase_14 | AC | 127 ms
11,264 KB |
testcase_15 | AC | 526 ms
11,648 KB |
testcase_16 | AC | 867 ms
12,032 KB |
testcase_17 | AC | 913 ms
12,416 KB |
testcase_18 | AC | 854 ms
12,288 KB |
testcase_19 | AC | 854 ms
12,160 KB |
testcase_20 | AC | 570 ms
12,288 KB |
testcase_21 | AC | 671 ms
11,776 KB |
testcase_22 | AC | 548 ms
13,056 KB |
testcase_23 | AC | 622 ms
12,288 KB |
testcase_24 | AC | 516 ms
12,928 KB |
testcase_25 | AC | 494 ms
12,928 KB |
testcase_26 | AC | 591 ms
13,056 KB |
testcase_27 | AC | 645 ms
13,412 KB |
testcase_28 | AC | 651 ms
13,412 KB |
testcase_29 | AC | 651 ms
13,284 KB |
testcase_30 | AC | 981 ms
13,668 KB |
testcase_31 | AC | 963 ms
13,540 KB |
testcase_32 | AC | 97 ms
11,136 KB |
testcase_33 | AC | 39 ms
10,752 KB |
testcase_34 | AC | 33 ms
10,752 KB |
testcase_35 | AC | 113 ms
11,264 KB |
testcase_36 | AC | 58 ms
10,880 KB |
testcase_37 | AC | 90 ms
11,264 KB |
testcase_38 | AC | 162 ms
11,648 KB |
testcase_39 | AC | 63 ms
11,008 KB |
testcase_40 | AC | 80 ms
11,136 KB |
testcase_41 | AC | 564 ms
13,044 KB |
testcase_42 | AC | 345 ms
11,776 KB |
testcase_43 | AC | 83 ms
10,880 KB |
testcase_44 | AC | 168 ms
11,648 KB |
testcase_45 | AC | 46 ms
10,752 KB |
testcase_46 | AC | 547 ms
13,056 KB |
ソースコード
import itertools import sys input = sys.stdin.readline N,M,K = map(int,input().split()) R = [i-1 for i in map(int,input().split())] INF = 10**9 dist = [[INF]*N for _ in [0]*N] route = [[0]*2 for _ in [0]*M] for i in range(M): A,B,C = map(int,input().split()) A -= 1; B -= 1 route[i] = [A,B,C] dist[A][B] = dist[B][A] = C def warshall_floyd(dist): for i in range(N): dist[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): d = dist[i][k]+dist[k][j] if(dist[i][j] > d): dist[i][j] = d return 0 warshall_floyd(dist) ans = INF rsum = sum(route[i][2] for i in R) for rlist in itertools.permutations(R): for bit in range(1 << K): s = rsum path = [0] for i in range(K): if(bit & (1 << i)): path.append(route[rlist[i]][0]) path.append(route[rlist[i]][1]) else: path.append(route[rlist[i]][1]) path.append(route[rlist[i]][0]) path.append(N-1) s += sum(dist[path[i]][path[i+1]] for i in range(0,len(path)-1,2)) if(ans > s): ans = s print(ans)