結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-10-05 17:04:07 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 798 ms / 2,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 21,544 KB |
最終ジャッジ日時 | 2024-05-01 17:24:28 |
合計ジャッジ時間 | 8,783 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
11,008 KB |
testcase_01 | AC | 45 ms
11,008 KB |
testcase_02 | AC | 27 ms
11,008 KB |
testcase_03 | AC | 27 ms
11,008 KB |
testcase_04 | AC | 27 ms
11,008 KB |
testcase_05 | AC | 27 ms
10,880 KB |
testcase_06 | AC | 28 ms
10,880 KB |
testcase_07 | AC | 28 ms
10,880 KB |
testcase_08 | AC | 26 ms
11,008 KB |
testcase_09 | AC | 58 ms
11,008 KB |
testcase_10 | AC | 31 ms
11,136 KB |
testcase_11 | AC | 35 ms
11,776 KB |
testcase_12 | AC | 66 ms
12,160 KB |
testcase_13 | AC | 55 ms
11,776 KB |
testcase_14 | AC | 130 ms
12,544 KB |
testcase_15 | AC | 31 ms
11,008 KB |
testcase_16 | AC | 57 ms
11,136 KB |
testcase_17 | AC | 51 ms
11,136 KB |
testcase_18 | AC | 49 ms
11,136 KB |
testcase_19 | AC | 49 ms
11,264 KB |
testcase_20 | AC | 127 ms
14,848 KB |
testcase_21 | AC | 54 ms
11,776 KB |
testcase_22 | AC | 267 ms
18,432 KB |
testcase_23 | AC | 169 ms
14,976 KB |
testcase_24 | AC | 369 ms
17,528 KB |
testcase_25 | AC | 381 ms
17,388 KB |
testcase_26 | AC | 585 ms
18,876 KB |
testcase_27 | AC | 636 ms
19,712 KB |
testcase_28 | AC | 517 ms
19,656 KB |
testcase_29 | AC | 738 ms
19,732 KB |
testcase_30 | AC | 798 ms
21,512 KB |
testcase_31 | AC | 546 ms
21,544 KB |
testcase_32 | AC | 112 ms
12,032 KB |
testcase_33 | AC | 33 ms
11,136 KB |
testcase_34 | AC | 33 ms
11,136 KB |
testcase_35 | AC | 46 ms
12,800 KB |
testcase_36 | AC | 61 ms
11,392 KB |
testcase_37 | AC | 41 ms
12,160 KB |
testcase_38 | AC | 185 ms
13,184 KB |
testcase_39 | AC | 71 ms
11,392 KB |
testcase_40 | AC | 78 ms
12,288 KB |
testcase_41 | AC | 138 ms
18,528 KB |
testcase_42 | AC | 115 ms
14,208 KB |
testcase_43 | AC | 77 ms
11,904 KB |
testcase_44 | AC | 147 ms
13,440 KB |
testcase_45 | AC | 49 ms
11,264 KB |
testcase_46 | AC | 215 ms
17,664 KB |
ソースコード
import sys import itertools import heapq as hq N,M,K = map(int,sys.stdin.readline().split()) R = [i-1 for i in map(int,sys.stdin.readline().split())] route = [[] for _ in [0]*N] edge = [0]*M for i in range(M): A,B,C = map(int,sys.stdin.readline().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 = hq.heappop(q) if(path[v] == -1): path[v] = d if(v == finish): break for nv,dist in route[v]: hq.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)