結果

問題 No.807 umg tours
ユーザー paruki
提出日時 2019-03-23 19:38:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 659 ms / 4,000 ms
コード長 2,068 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 181,316 KB
実行使用メモリ 45,528 KB
最終ジャッジ日時 2024-11-23 19:19:45
合計ジャッジ時間 9,339 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

typedef ll Weight;
struct Edge {
    int from, to;
    Weight wei;
    Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const Weight INFW = numeric_limits<Weight>::max();

vector<Weight> dijkstra(const Graph &G, int src) {
    typedef pair<Weight, int> pwi;
    priority_queue<pwi, vector<pwi>, greater<pwi>> pq;
    pq.push(mp(0, src));
    int V = (int)G.size();
    vector<Weight> res(V, -1);
    while (pq.size()) {
        auto p = pq.top(); pq.pop();
        Weight d = p.first;
        int v = p.second;
        if (res[v] > -1)continue;
        res[v] = d;
        for (const auto &edge : G[v]) {
            int to = edge.to;
            Weight wei = edge.wei;
            pq.push(make_pair(d + wei, to));
        }
    }
    return res;
}

void solve() {
    int N, M;
    cin >> N >> M;

    Graph G(2*N);

    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].emplace_back(a, b, c);
        G[b].emplace_back(b, a, c);
        G[a + N].emplace_back(a + N, b + N, c);
        G[b + N].emplace_back(b + N, a + N, c);
        G[a].emplace_back(a, b + N, 0);
        G[b].emplace_back(b, a + N, 0);
    }

    auto D = dijkstra(G, 0);
    cout << 0 << endl;
    FOR(i, 1, N) {
        cout << D[i] + D[i + N] << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}
0