結果

問題 No.807 umg tours
ユーザー NOSSNOSS
提出日時 2019-03-22 21:45:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 535 ms / 4,000 ms
コード長 1,683 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 179,028 KB
実行使用メモリ 24,464 KB
最終ジャッジ日時 2024-05-02 23:18:43
合計ジャッジ時間 8,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 284 ms
16,220 KB
testcase_12 AC 295 ms
14,512 KB
testcase_13 AC 394 ms
17,600 KB
testcase_14 AC 165 ms
9,916 KB
testcase_15 AC 133 ms
8,192 KB
testcase_16 AC 404 ms
18,552 KB
testcase_17 AC 513 ms
23,468 KB
testcase_18 AC 512 ms
23,520 KB
testcase_19 AC 497 ms
20,340 KB
testcase_20 AC 301 ms
12,612 KB
testcase_21 AC 314 ms
12,928 KB
testcase_22 AC 127 ms
7,552 KB
testcase_23 AC 99 ms
6,528 KB
testcase_24 AC 306 ms
21,120 KB
testcase_25 AC 535 ms
24,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll n, m;
ll dmin[2][MAX_N];
vector<vector<P> > g;

void dijkstra(){
    REP(i,2)fill(dmin[i],dmin[i]+n,LLINF/3);
    dmin[0][0] = 0;
    dmin[1][0] = 0;
    priority_queue<P3, vector<P3>, greater<P3> > que;
    que.push({0,{0,0}});
    while(!que.empty()){
        P3 p = que.top();
        que.pop();
        ll f = p.second.first, u = p.second.second;
        if(dmin[f][u] < p.first)continue;
        for(auto e : g[u]){
            ll v = e.first, cost = e.second;
            if(dmin[f][v] > dmin[f][u] + cost){
                dmin[f][v] = dmin[f][u] + cost;
                que.push({dmin[f][v], {f, v}});
            }
            if(f==0 && dmin[1][v] > dmin[0][u]){
                dmin[1][v] = dmin[0][u];
                que.push({dmin[1][v], {1, v}});
            }
        }
    }
}

int main() {
    cin >> n >> m;
    g.resize(n);
    REP(i,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    dijkstra();
    REP(i,n){
        cout << dmin[0][i] + dmin[1][i] << endl;
    }
    return 0;
}
0