結果

問題 No.807 umg tours
ユーザー TAISA_TAISA_
提出日時 2019-03-22 21:36:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,390 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 180,084 KB
実行使用メモリ 34,784 KB
最終ジャッジ日時 2023-08-15 11:51:44
合計ジャッジ時間 13,726 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 310 ms
17,216 KB
testcase_12 AC 338 ms
17,352 KB
testcase_13 AC 447 ms
19,840 KB
testcase_14 AC 179 ms
10,876 KB
testcase_15 AC 133 ms
9,144 KB
testcase_16 AC 465 ms
20,856 KB
testcase_17 AC 628 ms
26,608 KB
testcase_18 AC 596 ms
26,988 KB
testcase_19 AC 585 ms
23,536 KB
testcase_20 AC 342 ms
16,040 KB
testcase_21 AC 361 ms
16,668 KB
testcase_22 AC 136 ms
9,088 KB
testcase_23 AC 102 ms
7,628 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
struct edge {
    int to;
    ll cost;
};
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> G(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> q;
    vector<vector<ll>> d(n, vector<ll>(2, LINF));
    d[0][0] = 0;
    d[0][1] = 0;
    q.push(mp(P(0, 0), 0));
    q.push(mp(P(0, 0), 1));
    while(!q.empty()) {
        auto p = q.top();
        q.pop();
        int v = p.first.second, f = p.second;
        for(auto e : G[v]) {
            if(d[e.to][f] > d[v][f] + e.cost) {
                d[e.to][f] = d[v][f] + e.cost;
                q.push(mp(P(d[e.to][f], e.to), f));
            }
            if(f == 0) {
                if(d[e.to][1] > d[v][0]) {
                    d[e.to][1] = d[v][0];
                    q.push(mp(P(d[e.to][1], e.to), 1));
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        cout << d[i][0] + d[i][1] << endl;
    }
}
0