結果

問題 No.807 umg tours
ユーザー kyort0n
提出日時 2019-03-25 02:48:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 581 ms / 4,000 ms
コード長 1,357 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 173,776 KB
実行使用メモリ 25,372 KB
最終ジャッジ日時 2024-11-23 19:21:00
合計ジャッジ時間 8,689 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll dist[100500][2];
vector<l_l> pathes[100500];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        pathes[a].push_back({b, c});
        pathes[b].push_back({a, c});
    }
    priority_queue<l_l, vector<l_l>, greater<l_l> > que;
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= 1; j++) dist[i][j] = INF;
    }
    que.push({0, 1});
    que.push({0, 200001});
    while(!que.empty()) {
        l_l now = que.top();
        que.pop();
        int pos = now.second % (200000);
        int index = now.second / 200000;
        ll cost = now.first;
        if(dist[pos][index] <= cost) continue;
        dist[pos][index] = cost;
        for(int i = 0; i < pathes[pos].size(); i++) {
            l_l to = pathes[pos][i];
            que.push({cost + to.second, to.first + index * 200000});
            if(index == 0) {
                que.push({cost, to.first + 200000});
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        cout << dist[i][0] + dist[i][1] << endl;
    }
    return 0;
}
0