結果

問題 No.1812 Uribo Road
ユーザー erbowlerbowl
提出日時 2022-07-25 21:01:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 956 ms / 5,000 ms
コード長 2,298 bytes
コンパイル時間 3,125 ms
コンパイル使用メモリ 247,676 KB
実行使用メモリ 33,672 KB
最終ジャッジ日時 2023-09-22 07:01:52
合計ジャッジ時間 13,275 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 90 ms
8,324 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 18 ms
4,468 KB
testcase_10 AC 17 ms
4,524 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 832 ms
32,636 KB
testcase_13 AC 694 ms
29,000 KB
testcase_14 AC 539 ms
25,648 KB
testcase_15 AC 49 ms
6,412 KB
testcase_16 AC 141 ms
10,604 KB
testcase_17 AC 398 ms
18,492 KB
testcase_18 AC 651 ms
28,128 KB
testcase_19 AC 899 ms
33,672 KB
testcase_20 AC 956 ms
33,580 KB
testcase_21 AC 880 ms
33,648 KB
testcase_22 AC 869 ms
33,648 KB
testcase_23 AC 108 ms
8,268 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 24 ms
5,552 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 304 ms
16,324 KB
testcase_28 AC 41 ms
5,932 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 18 ms
4,488 KB
testcase_31 AC 868 ms
31,148 KB
testcase_32 AC 27 ms
4,760 KB
testcase_33 AC 210 ms
13,552 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