結果

問題 No.807 umg tours
ユーザー uchiiii
提出日時 2020-08-10 22:58:12
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,652 bytes
コンパイル時間 13,998 ms
コンパイル使用メモリ 293,424 KB
最終ジャッジ日時 2025-01-12 19:52:21
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
//-------------------
struct Edge {
    int to;
    ll cost;
    Edge(int to, ll ct): to(to), cost(ct) {}
};

using TIIL = tuple<ll, int, ll>;
constexpr int MX = 1e5+4;
vector<vector<Edge>> G(MX);
vector<ll> d1(MX, LINF);
vector<ll> d2(MX, LINF);

void dijkstra(int s, vector<ll> &d) {
    priority_queue<PII, vector<PII>, greater<PII> > que;
    que.push({0, s});

    while (!que.empty()) {
        PII p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] <= p.first) continue;
        d[v] = p.first;
        for (auto e: G[v]) {
            if (d[e.to] > d[v] + e.cost) { // make code faster
                que.push({d[v] + e.cost, e.to});
            }
        }
    }
}

void dijkstra2(int s, vector<ll> &d) {
    priority_queue<TIIL, vector<TIIL>, greater<TIIL> > que;
    que.push({0, s, 0});

    while (!que.empty()) {
        auto [ct, to, mx] = que.top();
        que.pop();
        if (d[to] <= ct) continue;
        // cout << to << " " << ct << mx << endl;
        d[to] = ct;
        for (auto &e: G[to]) {
            ll curmx = max(mx, e.cost);
            // cout << e.to << " " << d[e.to] << " " << d[to] + mx + e.cost - curmx << endl;
            if (d[e.to] > d[to] + mx + e.cost - curmx) { // make code faster
                que.push({d[to] + mx + e.cost - curmx, e.to, curmx});
                // cout << e.to << endl;
            }
        }
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int n,m; cin >> n >> m;
    rep(i, m) {
        int a,b; ll c; cin >> a >> b >> c;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
        // cout << G[a].back().to << " " << G[b].back().to << endl;
    }

    dijkstra(1, d1);
    dijkstra2(1, d2);

    FOR(i,1,n) {
        // cout << d1[i] << " ";
        cout << d1[i] + d2[i] << endl;
    }
    return 0;
}
0