結果

問題 No.807 umg tours
ユーザー TAISA_TAISA_
提出日時 2019-03-22 21:36:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,390 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 182,012 KB
実行使用メモリ 33,480 KB
最終ジャッジ日時 2024-05-02 23:17:29
合計ジャッジ時間 12,073 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 261 ms
16,712 KB
testcase_12 AC 271 ms
16,980 KB
testcase_13 AC 385 ms
20,172 KB
testcase_14 AC 165 ms
11,136 KB
testcase_15 AC 123 ms
9,292 KB
testcase_16 AC 390 ms
20,880 KB
testcase_17 AC 513 ms
26,884 KB
testcase_18 AC 483 ms
26,920 KB
testcase_19 AC 458 ms
23,884 KB
testcase_20 AC 293 ms
16,188 KB
testcase_21 AC 296 ms
16,640 KB
testcase_22 AC 119 ms
9,216 KB
testcase_23 AC 87 ms
7,808 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