結果

問題 No.1812 Uribo Road
ユーザー 👑 NachiaNachia
提出日時 2022-01-14 22:16:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 2,066 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 101,028 KB
実行使用メモリ 102,412 KB
最終ジャッジ日時 2024-04-30 15:21:44
合計ジャッジ時間 4,810 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 183 ms
99,968 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 15 ms
11,648 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 220 ms
101,256 KB
testcase_13 AC 174 ms
102,412 KB
testcase_14 AC 171 ms
102,288 KB
testcase_15 AC 31 ms
6,940 KB
testcase_16 AC 55 ms
22,656 KB
testcase_17 AC 145 ms
47,104 KB
testcase_18 AC 190 ms
100,704 KB
testcase_19 AC 282 ms
101,928 KB
testcase_20 AC 278 ms
101,280 KB
testcase_21 AC 259 ms
101,920 KB
testcase_22 AC 234 ms
101,936 KB
testcase_23 AC 36 ms
22,400 KB
testcase_24 AC 2 ms
6,948 KB
testcase_25 AC 12 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 81 ms
46,848 KB
testcase_28 AC 24 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 9 ms
6,944 KB
testcase_31 AC 223 ms
100,596 KB
testcase_32 AC 16 ms
11,392 KB
testcase_33 AC 192 ms
100,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)

template<class E>
using nega_queue = priority_queue<E,vector<E>,greater<E>>;

struct Edge{ int u,v,c; };
struct AdjEdge{ int to; i64 d; };

int N,M;
vector<Edge> J;
vector<vector<AdjEdge>> E;
int K;
vector<int> R;


vector<i64> dist(int s){
    nega_queue<pair<i64,int>> Q;
    vector<i64> D(E.size(), 1001001001001001001);
    Q.push({ 0,s });
    D[s] = 0;
    while(Q.size()){
        auto [d,p] = Q.top(); Q.pop();
        if(D[p] != d) continue;
        for(auto [to,dd] : E[p]){
            if(D[to] <= d+dd) continue;
            D[to] = d+dd;
            Q.push({ D[to],to });
        }
    }
    return D;
}


int main() {
    cin >> N >> M >> K;
    E.resize(N);
    J.resize(M);
    R.resize(K);
    rep(i,K){ cin >> R[i]; R[i]--; }
    rep(i,M){
        int u,v,c; cin >> u >> v >> c; u--; v--;
        J[i] = {u,v,c};
        E[u].push_back({v,c});
        E[v].push_back({u,c});
    }
    
    vector<int> Rp(K*2);
    rep(i,K) Rp[i*2] = J[R[i]].u;
    rep(i,K) Rp[i*2+1] = J[R[i]].v;

    vector<vector<AdjEdge>> G2(K*2 * (1<<K) + 2);
    const int ZG2 = K*2 * (1<<K);
    rep(i,K*2){
        auto D = dist(Rp[i]);
        rep(j,K*2){
            i64 d = D[Rp[j]];
            rep(b,1<<K) G2[(i<<K)+b].push_back({ (j<<K)+b, d });
        }
    }
    
    rep(k,K*2) rep(b,1<<K) G2[(k<<K)+b].push_back({ ((k^1)<<K)+(b|(1<<(k/2))), J[R[k/2]].c });

    {
        auto D = dist(0);
        rep(j,K*2) G2[ZG2].push_back({ j<<K, D[Rp[j]] });
    }
    {
        auto D = dist(N-1);
        rep(j,K*2) G2[((j+1)<<K)-1].push_back({ ZG2+1, D[Rp[j]] });
    }

    E = G2;
    auto D = dist(ZG2);
    i64 ans = D[ZG2+1];
    cout << ans << endl;

    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0