結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-10-17 11:41:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 605 ms / 2,000 ms |
コード長 | 1,165 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 124,080 KB |
最終ジャッジ日時 | 2024-11-21 22:50:56 |
合計ジャッジ時間 | 10,881 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,680 KB |
testcase_01 | AC | 66 ms
69,052 KB |
testcase_02 | AC | 42 ms
54,940 KB |
testcase_03 | AC | 39 ms
52,936 KB |
testcase_04 | AC | 40 ms
53,308 KB |
testcase_05 | AC | 41 ms
53,760 KB |
testcase_06 | AC | 50 ms
62,692 KB |
testcase_07 | AC | 40 ms
53,008 KB |
testcase_08 | AC | 46 ms
53,980 KB |
testcase_09 | AC | 129 ms
77,580 KB |
testcase_10 | AC | 95 ms
76,388 KB |
testcase_11 | AC | 112 ms
77,648 KB |
testcase_12 | AC | 175 ms
78,644 KB |
testcase_13 | AC | 164 ms
78,112 KB |
testcase_14 | AC | 244 ms
80,236 KB |
testcase_15 | AC | 123 ms
77,632 KB |
testcase_16 | AC | 160 ms
77,968 KB |
testcase_17 | AC | 193 ms
78,736 KB |
testcase_18 | AC | 154 ms
77,800 KB |
testcase_19 | AC | 108 ms
77,476 KB |
testcase_20 | AC | 223 ms
82,404 KB |
testcase_21 | AC | 199 ms
78,896 KB |
testcase_22 | AC | 328 ms
92,912 KB |
testcase_23 | AC | 253 ms
83,924 KB |
testcase_24 | AC | 374 ms
97,448 KB |
testcase_25 | AC | 365 ms
97,132 KB |
testcase_26 | AC | 466 ms
106,656 KB |
testcase_27 | AC | 527 ms
112,584 KB |
testcase_28 | AC | 422 ms
103,076 KB |
testcase_29 | AC | 605 ms
124,080 KB |
testcase_30 | AC | 492 ms
122,300 KB |
testcase_31 | AC | 393 ms
102,700 KB |
testcase_32 | AC | 231 ms
79,232 KB |
testcase_33 | AC | 99 ms
76,364 KB |
testcase_34 | AC | 98 ms
76,104 KB |
testcase_35 | AC | 125 ms
78,536 KB |
testcase_36 | AC | 153 ms
77,640 KB |
testcase_37 | AC | 118 ms
77,884 KB |
testcase_38 | AC | 252 ms
81,524 KB |
testcase_39 | AC | 179 ms
78,400 KB |
testcase_40 | AC | 198 ms
78,784 KB |
testcase_41 | AC | 195 ms
84,644 KB |
testcase_42 | AC | 219 ms
81,928 KB |
testcase_43 | AC | 185 ms
78,664 KB |
testcase_44 | AC | 223 ms
80,784 KB |
testcase_45 | AC | 167 ms
78,164 KB |
testcase_46 | AC | 267 ms
88,872 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)