結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2020-06-05 09:25:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 484 ms / 4,000 ms |
コード長 | 1,542 bytes |
コンパイル時間 | 2,174 ms |
コンパイル使用メモリ | 176,468 KB |
実行使用メモリ | 42,028 KB |
最終ジャッジ日時 | 2024-11-23 20:08:19 |
合計ジャッジ時間 | 7,887 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=(0);i<(n);i++)using namespace std;typedef long long ll;template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }struct edge {ll to, cost;};typedef pair<ll, ll> P; // firstはsからの最短距離, secondは頂点の番号struct dat{// sからの最短距離, 今の頂点の番号ll dis, idx;bool operator<(const dat & a) const{return dis > a.dis;}};const ll INF = 1e17;const int max_n = 202020;int n;vector<edge> g[max_n];void dijkstra(ll s, vector<ll> &d){rep(i, 2 * n) d[i] = INF;d[s] = 0;d[s + n] = 0;priority_queue<dat> que;que.push({0, s});while(!que.empty()){dat p = que.top();que.pop();ll v = p.idx;if(d[v] < p.dis) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれるfor(ll 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;que.push({d[e.to], e.to});}}}}int main(){cin.tie(0);ios::sync_with_stdio(false);int m;cin >> n >> m;rep(i, m){ll a, b, c;cin >> a >> b >> c;a--; b--;g[a].push_back({b, c});g[a].push_back({b+n, 0});g[a+n].push_back({b+n, c});g[b].push_back({a, c});g[b].push_back({a+n, 0});g[b+n].push_back({a+n, c});}vector<ll> d(2 * n);dijkstra(0, d);rep(i, n) cout << d[i] + d[i+n] << endl;}