結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-10-05 17:11:12 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,015 ms / 2,000 ms |
コード長 | 1,165 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 21,616 KB |
最終ジャッジ日時 | 2024-11-21 22:49:10 |
合計ジャッジ時間 | 10,826 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 54 ms
11,008 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 32 ms
10,880 KB |
testcase_05 | AC | 31 ms
11,008 KB |
testcase_06 | AC | 34 ms
10,880 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 32 ms
10,880 KB |
testcase_09 | AC | 62 ms
11,136 KB |
testcase_10 | AC | 39 ms
11,136 KB |
testcase_11 | AC | 45 ms
11,520 KB |
testcase_12 | AC | 79 ms
12,160 KB |
testcase_13 | AC | 68 ms
11,904 KB |
testcase_14 | AC | 154 ms
12,416 KB |
testcase_15 | AC | 38 ms
11,008 KB |
testcase_16 | AC | 61 ms
11,136 KB |
testcase_17 | AC | 60 ms
11,136 KB |
testcase_18 | AC | 58 ms
11,136 KB |
testcase_19 | AC | 57 ms
11,136 KB |
testcase_20 | AC | 168 ms
14,720 KB |
testcase_21 | AC | 64 ms
11,776 KB |
testcase_22 | AC | 341 ms
18,304 KB |
testcase_23 | AC | 197 ms
14,976 KB |
testcase_24 | AC | 424 ms
17,524 KB |
testcase_25 | AC | 455 ms
17,396 KB |
testcase_26 | AC | 711 ms
18,740 KB |
testcase_27 | AC | 777 ms
20,224 KB |
testcase_28 | AC | 672 ms
19,536 KB |
testcase_29 | AC | 948 ms
19,584 KB |
testcase_30 | AC | 1,015 ms
21,616 KB |
testcase_31 | AC | 712 ms
21,544 KB |
testcase_32 | AC | 123 ms
12,032 KB |
testcase_33 | AC | 37 ms
11,136 KB |
testcase_34 | AC | 36 ms
10,880 KB |
testcase_35 | AC | 59 ms
12,544 KB |
testcase_36 | AC | 70 ms
11,264 KB |
testcase_37 | AC | 48 ms
11,904 KB |
testcase_38 | AC | 210 ms
13,184 KB |
testcase_39 | AC | 79 ms
11,520 KB |
testcase_40 | AC | 92 ms
12,032 KB |
testcase_41 | AC | 175 ms
18,660 KB |
testcase_42 | AC | 137 ms
14,208 KB |
testcase_43 | AC | 92 ms
11,776 KB |
testcase_44 | AC | 172 ms
13,568 KB |
testcase_45 | AC | 56 ms
11,392 KB |
testcase_46 | AC | 264 ms
17,536 KB |
ソースコード
import itertools import heapq N,M,K = map(int,input().split()) R = [i-1 for i in map(int,input().split())] route = [[] for _ in [0]*N] edge = [0]*M for i in range(M): A,B,C = map(int,input().split()) A -= 1; B -= 1 edge[i] = [A,B,C] route[A].append((B,C)) route[B].append((A,C)) def dijkstra(route,start,finish,n): path = [-1]*n q = [(0,start)] while(q): d,v = heapq.heappop(q) if(path[v] == -1): path[v] = d if(v == finish): break for nv,dist in route[v]: heapq.heappush(q,(d+dist,nv)) return path[finish] ans = float("inf") rsum = sum(edge[i][2] for i in R) dist = [[0]*N for _ in [0]*N] 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(edge[rlist[i]][0]) path.append(edge[rlist[i]][1]) else: path.append(edge[rlist[i]][1]) path.append(edge[rlist[i]][0]) path.append(N-1) for i in range(0,len(path)-1,2): if(dist[path[i]][path[i+1]] == 0): dist[path[i]][path[i+1]] = dist[path[i+1]][path[i]] = dijkstra(route,path[i],path[i+1],N) s += dist[path[i]][path[i+1]] if(ans > s): ans = s print(ans)