結果

問題 No.807 umg tours
ユーザー face4face4
提出日時 2019-03-22 22:00:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 4,000 ms
コード長 1,113 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 83,568 KB
実行使用メモリ 19,052 KB
最終ジャッジ日時 2023-08-15 11:56:50
合計ジャッジ時間 7,573 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 310 ms
13,440 KB
testcase_12 AC 294 ms
11,120 KB
testcase_13 AC 398 ms
15,476 KB
testcase_14 AC 168 ms
8,760 KB
testcase_15 AC 130 ms
7,108 KB
testcase_16 AC 416 ms
14,200 KB
testcase_17 AC 522 ms
19,052 KB
testcase_18 AC 519 ms
18,992 KB
testcase_19 AC 503 ms
18,480 KB
testcase_20 AC 299 ms
11,172 KB
testcase_21 AC 303 ms
11,360 KB
testcase_22 AC 129 ms
6,704 KB
testcase_23 AC 97 ms
6,160 KB
testcase_24 AC 300 ms
16,456 KB
testcase_25 AC 517 ms
18,868 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