結果

問題 No.1814 Uribo Road (Easy)
ユーザー erbowlerbowl
提出日時 2022-07-26 20:27:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,298 bytes
コンパイル時間 2,915 ms
コンパイル使用メモリ 249,060 KB
実行使用メモリ 5,816 KB
最終ジャッジ日時 2023-09-23 11:15:52
合計ジャッジ時間 6,182 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 9 ms
4,396 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 16 ms
5,292 KB
testcase_23 AC 10 ms
4,488 KB
testcase_24 AC 15 ms
5,120 KB
testcase_25 AC 15 ms
5,092 KB
testcase_26 AC 17 ms
5,552 KB
testcase_27 AC 20 ms
5,516 KB
testcase_28 AC 19 ms
5,580 KB
testcase_29 AC 19 ms
5,576 KB
testcase_30 AC 20 ms
5,580 KB
testcase_31 AC 20 ms
5,816 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 15 ms
5,304 KB
testcase_42 AC 8 ms
4,500 KB
testcase_43 AC 4 ms
4,376 KB
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 15 ms
5,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll n,m,k;
    std::cin >> n>>m>>k;
    map<ll,bool> r;
    set<ll> ed;
    vector<tuple<ll,ll,ll>> rr;
    ed.insert(0);
    ed.insert(n-1);
    for (int i = 0; i < k; i++) {
        ll tmp;
        std::cin >> tmp;
        tmp--;
        r[tmp] = true;
    }
    
    vector<vector<tuple<ll,ll>>> edges(n);
    for (int i = 0; i < m; i++) {
        ll a,b,c;
        std::cin >> a>>b>>c;
        a--;b--;
        edges[a].push_back({b, c});
        edges[b].push_back({a, c});
        if(r[i]){
            ed.insert(a);
            ed.insert(b);
            rr.push_back({a,b,c});
        }
    }
    map<ll,vector<ll>> d;
    for (auto st : ed) {
        auto &dn = d[st];
        dn.resize(n,1e18);
        dn[st] = 0;
        priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
        pq.push({0, st});
        while(!pq.empty()){
            auto [dis, pos] = pq.top();pq.pop();
            if(dn[pos]<dis)continue;
            for (auto e : edges[pos]) {
                auto [v, c] = e;
                if(dn[v]>dis+c){
                    dn[v] = dis+c;
                    pq.push({dn[v],v});
                }
            }
        }
    }
    vector<vector<vector<ll>>> dp(1<<k, vector<vector<ll>>(ed.size(), vector<ll>(ed.size(), 1e18)));
    ll cntt = 0;
    map<ll,ll> con,con2;
    for (auto e : ed) {
        con[e] = cntt;
        con2[cntt] = e;
        cntt++;
    }
    for (int i = 0; i < ed.size(); i++) {
        dp[0][0][i] = d[0][con2[i]];
    }
    
    for (int i = 0; i < (1<<k); i++) {
        for (int j = 0; j < ed.size(); j++) {
            for (int l = 0; l < ed.size(); l++) {
                for (int bit = 0; bit < k; bit++) {
                    if(i>>bit&1){
                        auto [a,b,c] = rr[bit];
                        dp[i][j][l] = min(dp[i][j][l], dp[i&~(1<<bit)][j][con[a]]+d[b][con2[l]]+c);
                        dp[i][j][l] = min(dp[i][j][l], dp[i&~(1<<bit)][j][con[b]]+d[a][con2[l]]+c);
                        // std::cout << dp[i][j][l] << std::endl;
                    }
                }
            }
        }
    }
    std::cout << dp[(1<<k)-1][0][ed.size()-1]<< std::endl;
}
0