結果

問題 No.807 umg tours
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-27 16:03:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,690 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 189,192 KB
実行使用メモリ 21,408 KB
最終ジャッジ日時 2024-04-27 16:55:00
合計ジャッジ時間 8,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 241 ms
11,936 KB
testcase_12 AC 251 ms
13,536 KB
testcase_13 AC 315 ms
17,096 KB
testcase_14 AC 147 ms
10,128 KB
testcase_15 AC 130 ms
8,320 KB
testcase_16 AC 352 ms
18,660 KB
testcase_17 AC 446 ms
21,408 KB
testcase_18 AC 420 ms
20,264 KB
testcase_19 AC 428 ms
20,336 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 273 ms
19,364 KB
testcase_25 AC 409 ms
20,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

// dijkstra法
struct edge { int to, cost; };
vector<vector<edge>> G;//グラフ
vector<vector<int>> d;//sからの距離(INFで初期化)

void dijkstra(int s) {
    priority_queue<tuple<int, int,int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
    d[s][0] = d[s][1] = 0;
    pq.push(tuple<int, int, int>(0, 0, s));
    pq.push(tuple<int, int, int>(0, 1, s));
    while (!pq.empty()) {
        tuple<int, int, int> p = pq.top(); pq.pop();
        int v = get<2>(p);
        if (d[v][get<1>(p)] < get<0>(p)) continue;
        for (edge e : G[v])
        {
            if (d[e.to][0] > d[v][0] + e.cost) {
                d[e.to][0] = d[v][0] + e.cost;
                pq.push({d[e.to][0],0, e.to});
            }
            if (d[e.to][1] > d[v][0] || d[e.to][1] > d[v][1] + e.cost) {
                d[e.to][1] = min(d[v][0],d[v][1] + e.cost);
                pq.push({d[e.to][1],1, e.to});
            }
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    G.resize(n);
    d.resize(n,vector<int>(2,INF));
    REP(i, m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    dijkstra(0);
    REP(i, n) {
        cout << d[i][0] + d[i][1] << endl;
    }
    getchar(); getchar();
}
0