結果

問題 No.1690 Power Grid
ユーザー 👑 KazunKazun
提出日時 2021-09-24 22:49:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 831 ms / 3,000 ms
コード長 829 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 90,288 KB
最終ジャッジ日時 2023-09-18 21:55:07
合計ジャッジ時間 13,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,396 KB
testcase_01 AC 80 ms
71,132 KB
testcase_02 AC 98 ms
76,800 KB
testcase_03 AC 76 ms
71,352 KB
testcase_04 AC 75 ms
71,268 KB
testcase_05 AC 75 ms
71,060 KB
testcase_06 AC 494 ms
81,328 KB
testcase_07 AC 494 ms
81,056 KB
testcase_08 AC 535 ms
83,912 KB
testcase_09 AC 530 ms
83,732 KB
testcase_10 AC 660 ms
83,960 KB
testcase_11 AC 495 ms
81,276 KB
testcase_12 AC 77 ms
71,128 KB
testcase_13 AC 102 ms
77,012 KB
testcase_14 AC 171 ms
78,172 KB
testcase_15 AC 758 ms
85,932 KB
testcase_16 AC 646 ms
81,824 KB
testcase_17 AC 476 ms
81,692 KB
testcase_18 AC 239 ms
79,796 KB
testcase_19 AC 669 ms
81,248 KB
testcase_20 AC 633 ms
84,912 KB
testcase_21 AC 831 ms
87,404 KB
testcase_22 AC 666 ms
81,704 KB
testcase_23 AC 631 ms
81,364 KB
testcase_24 AC 726 ms
85,080 KB
testcase_25 AC 810 ms
87,512 KB
testcase_26 AC 688 ms
90,288 KB
testcase_27 AC 75 ms
71,120 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):
    for i in range(N):
        for j in range(N):
            T[i][j]=min(T[i][j], T[i][k]+T[k][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=[]
    for x in range(N):
        if (S>>x)&1:
            U.append(x)
        else:
            V.append(x)

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

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

popcount=lambda x:bin(x).count("1")

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

print(X)
0