結果

問題 No.807 umg tours
ユーザー xuzijian629xuzijian629
提出日時 2019-03-22 22:53:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 216,220 KB
実行使用メモリ 21,960 KB
最終ジャッジ日時 2023-10-19 10:07:55
合計ジャッジ時間 11,635 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
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 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        adj[a].emplace_back(b, c);
        adj[b].emplace_back(a, c);
    }
    vector<vector<long long>> dist(n, vector<long long>(2, 1e18));
    using P = pair<long long, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, 0);
    dist[0][0] = dist[0][1] = 0;
    while (que.size()) {
        P top = que.top();
        que.pop();
        int u = top.second;
        long long d = top.first;
        for (auto& p : adj[u]) {
            int v = p.first, w = p.second;
            dist[v][1] = min(dist[v][1], d);
            if (d + w < dist[v][0]) {
                dist[v][0] = d + w;
                que.emplace(d + w, v);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << dist[i][0] + dist[i][1] << '\n';
    }
}
0