結果

問題 No.807 umg tours
ユーザー uchiiiiuchiiii
提出日時 2020-08-11 00:04:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 4,000 ms
コード長 2,035 bytes
コンパイル時間 3,663 ms
コンパイル使用メモリ 227,240 KB
実行使用メモリ 43,344 KB
最終ジャッジ日時 2023-08-15 12:56:07
合計ジャッジ時間 7,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,220 KB
testcase_01 AC 4 ms
9,360 KB
testcase_02 AC 4 ms
9,512 KB
testcase_03 AC 4 ms
9,524 KB
testcase_04 AC 3 ms
9,284 KB
testcase_05 AC 4 ms
9,124 KB
testcase_06 AC 4 ms
9,516 KB
testcase_07 AC 5 ms
9,344 KB
testcase_08 AC 3 ms
9,180 KB
testcase_09 AC 4 ms
9,124 KB
testcase_10 AC 5 ms
9,012 KB
testcase_11 AC 191 ms
38,908 KB
testcase_12 AC 155 ms
26,268 KB
testcase_13 AC 229 ms
37,488 KB
testcase_14 AC 84 ms
20,788 KB
testcase_15 AC 64 ms
18,064 KB
testcase_16 AC 244 ms
36,560 KB
testcase_17 AC 310 ms
41,524 KB
testcase_18 AC 301 ms
42,764 KB
testcase_19 AC 317 ms
41,952 KB
testcase_20 AC 121 ms
22,992 KB
testcase_21 AC 125 ms
23,376 KB
testcase_22 AC 50 ms
15,572 KB
testcase_23 AC 40 ms
14,152 KB
testcase_24 AC 108 ms
33,452 KB
testcase_25 AC 313 ms
43,344 KB
権限があれば一括ダウンロードができます

ソースコード

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<ll, 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) {}
};

constexpr int MX = 2e5+4;
vector<vector<Edge>> G(MX);
vector<ll> d1(MX, LINF);
int n,m; 

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

    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});
            }
        }
    }
}


int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    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);
        G[a].emplace_back(b+n, 0);
        G[b].emplace_back(a+n, 0);
        G[a+n].emplace_back(b+n, c);
        G[b+n].emplace_back(a+n, c);
        // cout << G[a].back().to << " " << G[b].back().to << endl;
    }

    dijkstra(1, d1);

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