結果

問題 No.807 umg tours
ユーザー face4face4
提出日時 2019-03-22 22:00:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 477 ms / 4,000 ms
コード長 1,113 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 84,920 KB
実行使用メモリ 18,480 KB
最終ジャッジ日時 2024-05-02 23:22:16
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 294 ms
13,428 KB
testcase_12 AC 254 ms
11,332 KB
testcase_13 AC 367 ms
15,276 KB
testcase_14 AC 153 ms
9,040 KB
testcase_15 AC 123 ms
7,556 KB
testcase_16 AC 384 ms
14,380 KB
testcase_17 AC 470 ms
18,392 KB
testcase_18 AC 477 ms
18,268 KB
testcase_19 AC 439 ms
18,480 KB
testcase_20 AC 248 ms
11,172 KB
testcase_21 AC 271 ms
11,452 KB
testcase_22 AC 109 ms
6,876 KB
testcase_23 AC 85 ms
6,144 KB
testcase_24 AC 284 ms
16,612 KB
testcase_25 AC 473 ms
18,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll INF = 1ll<<60;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v[n];
    int a, b, c;
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--, b--;
        v[a].push_back({b, c});
        v[b].push_back({a, c});
    }
    vector<vector<ll>> d(2, vector<ll>(n, INF));
    priority_queue<pair<ll, pair<int, int>>> pq;
    pq.push({-0, {0, 0}});
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        ll cost = -p.first;
        int pos = p.second.first, used = p.second.second;
        if(d[used][pos] <= cost)    continue;
        d[used][pos] = cost;
        for(pair<int,int> path : v[pos]){
            ll ncost = cost + path.second;
            int next = path.first;
            if(d[used][next] > ncost)   pq.push({-ncost, {next, used}});
            if(used == 0 && d[1][next] > cost)  pq.push({-cost, {next, 1}});
        }
    }
    cout << 0 << endl;
    for(int i = 1; i < n; i++){
        cout << d[1][i]+d[0][i] << endl;
    }
    return 0;
}
0