結果
問題 | 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
|
実行時間 | 959 ms / 2,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 21,416 KB |
最終ジャッジ日時 | 2024-11-21 22:48:58 |
合計ジャッジ時間 | 10,601 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 53 ms
10,880 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 32 ms
11,008 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 32 ms
10,880 KB |
testcase_06 | AC | 34 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,880 KB |
testcase_08 | AC | 31 ms
10,880 KB |
testcase_09 | AC | 62 ms
11,008 KB |
testcase_10 | AC | 35 ms
11,264 KB |
testcase_11 | AC | 39 ms
11,648 KB |
testcase_12 | AC | 73 ms
12,032 KB |
testcase_13 | AC | 63 ms
11,776 KB |
testcase_14 | AC | 150 ms
12,288 KB |
testcase_15 | AC | 37 ms
11,008 KB |
testcase_16 | AC | 60 ms
11,136 KB |
testcase_17 | AC | 61 ms
11,136 KB |
testcase_18 | AC | 58 ms
11,136 KB |
testcase_19 | AC | 59 ms
11,136 KB |
testcase_20 | AC | 153 ms
14,848 KB |
testcase_21 | AC | 61 ms
11,648 KB |
testcase_22 | AC | 312 ms
18,304 KB |
testcase_23 | AC | 181 ms
15,104 KB |
testcase_24 | AC | 401 ms
17,268 KB |
testcase_25 | AC | 412 ms
17,516 KB |
testcase_26 | AC | 608 ms
18,748 KB |
testcase_27 | AC | 716 ms
19,584 KB |
testcase_28 | AC | 626 ms
19,528 KB |
testcase_29 | AC | 882 ms
19,608 KB |
testcase_30 | AC | 959 ms
21,384 KB |
testcase_31 | AC | 676 ms
21,416 KB |
testcase_32 | AC | 122 ms
11,904 KB |
testcase_33 | AC | 38 ms
11,264 KB |
testcase_34 | AC | 37 ms
11,008 KB |
testcase_35 | AC | 53 ms
12,544 KB |
testcase_36 | AC | 71 ms
11,264 KB |
testcase_37 | AC | 46 ms
12,160 KB |
testcase_38 | AC | 209 ms
13,184 KB |
testcase_39 | AC | 80 ms
11,520 KB |
testcase_40 | AC | 89 ms
12,160 KB |
testcase_41 | AC | 145 ms
18,660 KB |
testcase_42 | AC | 122 ms
13,952 KB |
testcase_43 | AC | 89 ms
11,904 KB |
testcase_44 | AC | 163 ms
13,568 KB |
testcase_45 | AC | 55 ms
11,520 KB |
testcase_46 | AC | 236 ms
17,536 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)