結果

問題 No.1690 Power Grid
ユーザー yakkiyakki
提出日時 2021-09-24 22:50:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 3,000 ms
コード長 1,860 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 123,888 KB
実行使用メモリ 5,704 KB
最終ジャッジ日時 2023-09-18 21:55:50
合計ジャッジ時間 4,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,408 KB
testcase_01 AC 3 ms
5,396 KB
testcase_02 AC 3 ms
5,468 KB
testcase_03 AC 3 ms
5,584 KB
testcase_04 AC 3 ms
5,484 KB
testcase_05 AC 3 ms
5,464 KB
testcase_06 AC 124 ms
5,488 KB
testcase_07 AC 125 ms
5,680 KB
testcase_08 AC 125 ms
5,448 KB
testcase_09 AC 124 ms
5,400 KB
testcase_10 AC 124 ms
5,472 KB
testcase_11 AC 124 ms
5,456 KB
testcase_12 AC 3 ms
5,596 KB
testcase_13 AC 3 ms
5,400 KB
testcase_14 AC 15 ms
5,404 KB
testcase_15 AC 124 ms
5,392 KB
testcase_16 AC 124 ms
5,400 KB
testcase_17 AC 59 ms
5,392 KB
testcase_18 AC 29 ms
5,704 KB
testcase_19 AC 124 ms
5,444 KB
testcase_20 AC 124 ms
5,392 KB
testcase_21 AC 124 ms
5,556 KB
testcase_22 AC 124 ms
5,396 KB
testcase_23 AC 124 ms
5,444 KB
testcase_24 AC 124 ms
5,392 KB
testcase_25 AC 124 ms
5,460 KB
testcase_26 AC 124 ms
5,408 KB
testcase_27 AC 3 ms
5,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-18;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {-1,1,0,0};
int dw[] = {0,0,1,-1};

void WarshallFloyd(vector<vector<ll>> &dist){
    int N = dist.size();
	rep(k,N)rep(i,N){
		if(dist[i][k] == LINF) continue;
		rep(j,N){
			if(dist[k][j] == LINF) continue;
			dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
		}
	}
}

ll dp[1<<18];

int main(){
    int n,m,k; cin >> n >> m >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector dist(n,vector<ll>(n,LINF));
    rep(i,m){
        int x,y,z; cin >> x >> y >> z;
        x--; y--;
        dist[x][y] = dist[y][x] = z;
    }
    rep(i,n) dist[i][i] = 0;

    WarshallFloyd(dist);

    rep(i,1<<18) dp[i] = LINF;
    dp[0]= 0;
    rep(j,1<<n)rep(i,n){
        if(j>>i&1) continue;
        ll cost = LINF;
        rep(l,n){
            if(j>>l&1) cost = min(cost,dist[l][i]);
        }
        if(cost == LINF) cost = 0;
        cost += a[i];
        dp[j|(1<<i)] = min(dp[j|(1<<i)],dp[j]+cost);
    }
    ll ans = LINF;
    rep(i,1<<n){
        int cnt = __builtin_popcount(i);
        if(cnt == k){
            ans = min(ans,dp[i]);
        }
    }
    cout << ans << endl;
}
0