結果

問題 No.1812 Uribo Road
ユーザー erbowlerbowl
提出日時 2022-07-24 17:44:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,634 ms
コンパイル使用メモリ 221,692 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-20 17:30:57
合計ジャッジ時間 11,594 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 14 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 27 ms
4,380 KB
testcase_09 AC 54 ms
4,804 KB
testcase_10 AC 19 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
ll k;
ll cpos(ll e, ll bin){
    return (e<<k)+bin;
}

signed main(){
    ll n,m;
    std::cin >> n>>m>>k;
    vector<ll> r(k);
    map<ll,ll> rr;
    for (int i = 0; i < k; i++) {
        std::cin >> r[i];
        r[i]--;
        rr[r[i]]=i;
    }
    vector<vector<tuple<ll,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({i, b,c});
        edges[b].push_back({i, a,c});
    }
    vector<ll> d(n<<k,1e18);
    d[0] = 0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
    pq.push({0,0});
    while(!pq.empty()){
        auto [dis, pos] = pq.top();pq.pop();
        ll bin = ((1<<k)-1)&pos;
        if(d[pos]<dis)continue;
        for (auto e : edges[pos>>k]) {
            auto [ind, nex, cost] = e;
            if(rr.find(ind)!=rr.end()){
                if(d[cpos(nex, bin|(1<<rr[ind]))]>dis+cost){
                    d[cpos(nex, bin|(1<<rr[ind]))] = dis+cost;
                    pq.push({dis+cost, cpos(nex, bin|(1<<rr[ind]))});
                }
            }else{
                if(d[cpos(nex, bin)] > dis+cost){
                    d[cpos(nex, bin)] = dis+cost;
                    pq.push({dis+cost, cpos(nex,bin)});
                } 
            }
        }
    }
    std::cout << d[cpos(n-1, (1<<k)-1)] << std::endl;
}
0