結果

問題 No.807 umg tours
ユーザー kya_skikya_ski
提出日時 2019-10-26 18:49:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,664 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 181,072 KB
実行使用メモリ 56,612 KB
最終ジャッジ日時 2023-10-12 17:21:32
合計ジャッジ時間 10,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}
const long long INF = 1e12;

vector<long long> dijkstra(const Graph &g, int s) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main(){
    int N, M;
    cin >> N >> M;
    Graph G(N, vector<edge>());
    Graph H(2 * N, vector<edge>());
    for (int i = 0; i < M; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(make_pair(b, c));
        G[b].push_back(make_pair(a, c));
        H[a].push_back(make_pair(b, c));
        H[b].push_back(make_pair(a, c));
        H[N + a].push_back(make_pair(N + b, c));
        H[N + b].push_back(make_pair(N + a, c));
        if(b != 0)H[a].push_back(make_pair(N + b, 0LL));
        if(a != 0)H[b].push_back(make_pair(N + a, 0LL));
    }
    
    vector<long long> time2 = dijkstra(H, 0);
    for (int i = 0; i < N; i++) {
        cout << time2[i] + time2[i + N] << endl;
    }
    return 0;
}
    
0