結果

問題 No.1690 Power Grid
ユーザー 👑 KazunKazun
提出日時 2021-09-25 01:33:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 662 ms / 3,000 ms
コード長 936 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 92,136 KB
最終ジャッジ日時 2023-09-18 22:44:05
合計ジャッジ時間 11,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,484 KB
testcase_01 AC 75 ms
71,516 KB
testcase_02 AC 99 ms
76,808 KB
testcase_03 AC 76 ms
71,280 KB
testcase_04 AC 75 ms
71,116 KB
testcase_05 AC 75 ms
71,432 KB
testcase_06 AC 361 ms
81,400 KB
testcase_07 AC 364 ms
81,460 KB
testcase_08 AC 407 ms
85,764 KB
testcase_09 AC 404 ms
85,552 KB
testcase_10 AC 534 ms
85,832 KB
testcase_11 AC 361 ms
81,448 KB
testcase_12 AC 76 ms
71,468 KB
testcase_13 AC 105 ms
77,012 KB
testcase_14 AC 157 ms
78,160 KB
testcase_15 AC 629 ms
87,660 KB
testcase_16 AC 511 ms
81,800 KB
testcase_17 AC 403 ms
82,320 KB
testcase_18 AC 209 ms
79,828 KB
testcase_19 AC 533 ms
81,616 KB
testcase_20 AC 497 ms
86,880 KB
testcase_21 AC 662 ms
89,240 KB
testcase_22 AC 512 ms
81,812 KB
testcase_23 AC 496 ms
81,688 KB
testcase_24 AC 587 ms
86,408 KB
testcase_25 AC 642 ms
89,456 KB
testcase_26 AC 549 ms
92,136 KB
testcase_27 AC 75 ms
71,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K=map(int,input().split())
A=list(map(int,input().split()))

inf=float("inf")
T=[[inf]*N for _ in range(N)]

for _ in range(M):
    x,y,z=map(int,input().split())
    x-=1; y-=1
    T[x][y]=T[y][x]=z

# WF
for i in range(N):
    T[i][i]=0

for k in range(N):
    Tk=T[k]
    for i in range(N):
        Ti=T[i]
        for j in range(N):
            Ti[j]=min(Ti[j], Ti[k]+Tk[j])

DP=[inf]*(1<<N); DP[0]=0
for i in range(N):
    DP[1<<i]=A[i]

for S in range(1,1<<N):
    U=[]
    V=[]
    SS=S
    for x in range(N):
        if SS&1:
            U.append(x)
        else:
            V.append(x)
        SS>>=1

    for v in V:
        L=inf
        Tv=T[v]
        for u in U:
            L=min(L,Tv[u])

        DP[S|(1<<v)]=min(DP[S|1<<v], DP[S]+A[v]+L)

popcount=[0]*(1<<N)
for S in range(1,1<<N):
    x=S&(-S)
    popcount[S]=popcount[S^x]+1

X=inf
for S in range(1<<N):
    if popcount[S]==K:
        X=min(X,DP[S])

print(X)
0