結果

問題 No.1812 Uribo Road
ユーザー erbowlerbowl
提出日時 2022-07-25 20:57:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,168 bytes
コンパイル時間 3,571 ms
コンパイル使用メモリ 246,816 KB
実行使用メモリ 33,876 KB
最終ジャッジ日時 2023-09-22 06:58:00
合計ジャッジ時間 13,860 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 94 ms
8,240 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 9 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 580 ms
25,588 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 703 ms
27,916 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 213 ms
13,456 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)));
    dp[0][0][0] = 0;
    ll cntt = 0;
    map<ll,ll> con,con2;
    for (auto e : ed) {
        con[e] = cntt;
        con2[cntt] = e;
        cntt++;
    }
    
    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[(1<<k)-1][0][ed.size()-1]<< std::endl;
}
0