結果

問題 No.807 umg tours
ユーザー erbowlerbowl
提出日時 2019-03-22 22:35:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,189 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 169,380 KB
実行使用メモリ 23,148 KB
最終ジャッジ日時 2023-10-19 09:50:55
合計ジャッジ時間 8,261 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 6 ms
8,360 KB
testcase_07 WA -
testcase_08 AC 5 ms
8,312 KB
testcase_09 AC 6 ms
8,316 KB
testcase_10 AC 5 ms
8,324 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 318 ms
13,364 KB
testcase_21 AC 334 ms
13,556 KB
testcase_22 AC 135 ms
10,696 KB
testcase_23 AC 104 ms
10,156 KB
testcase_24 AC 300 ms
17,516 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<ll, ll> P;
struct edge {
    ll to;
    ll cost;
};
vector<edge> G[100010];
int main() {
    ll n,m;
    std::cin >> n>>m;
    ll d[100010];
    ll inf = 100000000000000+10;
    Fill(d,inf);
    d[0] = 0;
    for (int i = 0; i < m; i++) {
        ll tmp_a,tmp_b,tmp_c;
        std::cin >> tmp_a>>tmp_b>>tmp_c;
        tmp_a--;
        tmp_b--;
        edge e1 = {tmp_b,tmp_c};
        edge e2 = {tmp_a,tmp_c};
        G[tmp_a].push_back(e1);
        G[tmp_b].push_back(e2);
    }
    
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, 0));
    
    ll logest[100010];
    Fill(logest,0);
    
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                // logest[e.to] = max({logest[e.to],logest[v],e.cost});
                // std::cout << logest[e.to] << std::endl;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    
    // 最大距離消えるバージョン
    ll d2[100010];
    Fill(d2,inf);
    d2[0] = 0;
    priority_queue<P, vector<P>, greater<P> > que2;
    que2.push(P(0,0));
    while (!que2.empty()) {
        P p = que2.top();
        que2.pop();
        int v = p.second;
        if (d2[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            ll now_longest = max( logest[v], e.cost );
            if (d2[e.to]-logest[e.to] > d2[v] + e.cost - now_longest) {
                d2[e.to] = d2[v] + e.cost;
                logest[e.to] = max({logest[e.to],now_longest});
                // std::cout << logest[e.to] << std::endl;
                que2.push(P(d2[e.to], e.to));
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        std::cout << d[i]+d2[i] - logest[i] << std::endl;
    }
}
0