結果

問題 No.807 umg tours
ユーザー rogi52rogi52
提出日時 2022-10-10 06:45:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 555 ms / 4,000 ms
コード長 1,358 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 210,688 KB
実行使用メモリ 56,504 KB
最終ジャッジ日時 2023-09-06 07:57:07
合計ジャッジ時間 10,501 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 295 ms
41,948 KB
testcase_12 AC 276 ms
32,480 KB
testcase_13 AC 400 ms
44,400 KB
testcase_14 AC 148 ms
20,924 KB
testcase_15 AC 110 ms
17,356 KB
testcase_16 AC 425 ms
47,100 KB
testcase_17 AC 555 ms
56,000 KB
testcase_18 AC 540 ms
56,504 KB
testcase_19 AC 528 ms
53,432 KB
testcase_20 AC 248 ms
30,336 KB
testcase_21 AC 249 ms
31,408 KB
testcase_22 AC 96 ms
15,372 KB
testcase_23 AC 66 ms
12,708 KB
testcase_24 AC 177 ms
43,400 KB
testcase_25 AC 545 ms
56,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<vector<pair<int,ll>>> G(N), H(N + N);
    auto h = [](int v, int p) { return v * 2 + p; };
    rep(_,M) {
        int u,v,c; cin >> u >> v >> c; u--; v--;
        G[u].push_back({v, c});
        G[v].push_back({u, c});
        for(int p : {0, 1}) {
            H[h(u, p)].push_back({h(v, p), c});
            H[h(v, p)].push_back({h(u, p), c});
        }
        H[h(u, 0)].push_back({h(v, 1), 0});
        H[h(v, 0)].push_back({h(u, 1), 0});
    }

    auto distG = dijkstra(G, 0);
    auto distH = dijkstra(H, h(0, 0));
    rep(i,N) cout << distG[i] + min(distH[h(i, 0)], distH[h(i, 1)]) << "\n";
}
0