結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-11-07 12:51:45 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 442 ms / 2,000 ms |
コード長 | 1,442 bytes |
コンパイル時間 | 92 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 19,512 KB |
最終ジャッジ日時 | 2024-11-21 23:00:42 |
合計ジャッジ時間 | 7,241 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 46 ms
11,008 KB |
testcase_02 | AC | 36 ms
10,880 KB |
testcase_03 | AC | 34 ms
11,008 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 32 ms
11,008 KB |
testcase_06 | AC | 35 ms
11,008 KB |
testcase_07 | AC | 34 ms
11,008 KB |
testcase_08 | AC | 33 ms
11,136 KB |
testcase_09 | AC | 51 ms
11,136 KB |
testcase_10 | AC | 38 ms
11,264 KB |
testcase_11 | AC | 47 ms
11,648 KB |
testcase_12 | AC | 67 ms
12,160 KB |
testcase_13 | AC | 61 ms
11,776 KB |
testcase_14 | AC | 100 ms
12,288 KB |
testcase_15 | AC | 38 ms
11,264 KB |
testcase_16 | AC | 50 ms
11,264 KB |
testcase_17 | AC | 49 ms
11,264 KB |
testcase_18 | AC | 47 ms
11,392 KB |
testcase_19 | AC | 46 ms
11,264 KB |
testcase_20 | AC | 144 ms
13,952 KB |
testcase_21 | AC | 60 ms
11,648 KB |
testcase_22 | AC | 242 ms
16,768 KB |
testcase_23 | AC | 153 ms
14,336 KB |
testcase_24 | AC | 260 ms
16,128 KB |
testcase_25 | AC | 254 ms
16,256 KB |
testcase_26 | AC | 342 ms
17,280 KB |
testcase_27 | AC | 418 ms
17,920 KB |
testcase_28 | AC | 414 ms
18,048 KB |
testcase_29 | AC | 423 ms
17,920 KB |
testcase_30 | AC | 442 ms
19,392 KB |
testcase_31 | AC | 439 ms
19,512 KB |
testcase_32 | AC | 86 ms
11,776 KB |
testcase_33 | AC | 40 ms
11,136 KB |
testcase_34 | AC | 36 ms
11,008 KB |
testcase_35 | AC | 72 ms
12,416 KB |
testcase_36 | AC | 60 ms
11,520 KB |
testcase_37 | AC | 55 ms
12,032 KB |
testcase_38 | AC | 129 ms
12,800 KB |
testcase_39 | AC | 66 ms
11,520 KB |
testcase_40 | AC | 70 ms
11,904 KB |
testcase_41 | AC | 193 ms
17,024 KB |
testcase_42 | AC | 111 ms
13,440 KB |
testcase_43 | AC | 72 ms
11,776 KB |
testcase_44 | AC | 133 ms
12,928 KB |
testcase_45 | AC | 50 ms
11,392 KB |
testcase_46 | AC | 241 ms
16,512 KB |
ソースコード
import itertools import heapq INF = float("inf") N,M,K = map(int,input().split()) R = set([i-1 for i in map(int,input().split())]) lR = list(R) route = [[] for _ in [0]*N] edge = [0]*M st = set([0,N-1]) for i in range(M): A,B,C = map(int,input().split()) A -= 1; B -= 1 if(i in R): edge[i] = [A,B,C] st.add(A); st.add(B) if not(1 <= A+1 <= N and 1 <= B+1 <= N and 1 <= C <= 10**4): print((i,A+1,B+1,C)) exit(1) route[A].append((B,C)) route[B].append((A,C)) def dijkstra(route): dist = [[-1]*N for _ in [0]*N] for i in st: q = [(0,i)] cnt = 0 while(q and cnt < N): d,v = heapq.heappop(q) if(dist[i][v] == -1): cnt += 1 dist[i][v] = d for nv,nd in route[v]: heapq.heappush(q,(d + nd,nv)) return dist ans = INF rsum = sum(edge[i][2] for i in R) dist = dijkstra(route) for rbit in range(1 << K): b = [(rbit >> i) & 1 for i in range(K)] dp = [[INF]*K for i in range(1 << K)] for i in range(K): p = edge[lR[i]][b[i]] dp[1 << i][i] = dist[0][p] + rsum for bit in range(1, 1 << K): for s in range(K): p = edge[lR[s]][b[s]^1] if not(bit & (1 << s)): continue for t in range(K): np = edge[lR[t]][b[t]] k = bit | (1 << t) d = dp[bit][s] + dist[p][np] if((bit & (1 << t)) == 0 and dp[k][t] > d): dp[k][t] = d c = INF for i in range(K): p = edge[lR[i]][b[i]^1] d = dp[-1][i] + dist[p][N-1] if(c > d): c = d if(ans > c): ans = c print(ans)