結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2019-05-04 12:19:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 499 ms / 4,000 ms |
コード長 | 1,764 bytes |
コンパイル時間 | 1,193 ms |
コンパイル使用メモリ | 111,876 KB |
実行使用メモリ | 24,504 KB |
最終ジャッジ日時 | 2024-11-23 19:29:30 |
合計ジャッジ時間 | 7,725 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include <cstdlib> #include <math.h> #include <cmath> #include<cctype> #include<string> #include<set> #include<iomanip> #include <map> #include<algorithm> #include <functional> #include<vector> #include<climits> #include<stack> #include<queue> #include <deque> #include <climits> #include <typeinfo> #include <utility> #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair<ll, vector<int>>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; typedef tuple<ll, ll, ll>T; int n, m; vector<pair<ll, ll>>E[101010]; void dijkstra(int n,int m,vector<vector<ll>> &dp) { dp[0][0] = 0; dp[1][0] = 0; priority_queue<T,vector<T>,greater<T>>Q; Q.push({0,0,0}); Q.push({0,1,0}); while (!Q.empty()) { auto t = Q.top(); Q.pop(); ll cost = get<0>(t); ll state = get<1>(t); ll v = get<2>(t); if (cost > dp[state][v])continue; rep(i, 0, E[v].size()) { auto &e = E[v][i]; if (dp[state][e.first] > cost + e.second) { dp[state][e.first] = cost + e.second; Q.push({dp[state][e.first],state,e.first}); } if (state == 0) { if (dp[1][e.first] > cost) { dp[1][e.first] = cost; Q.push({dp[1][e.first],1,e.first}); } } } } } int main() { cin >> n >> m; rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; a--, b--; E[a].pb({b,c}); E[b].pb({a,c}); } vector<vector<ll>>dp(2,vector<ll>(n,inf)); dijkstra(n, m, dp); rep(i, 0, n) { cout << dp[0][i] + dp[1][i] << endl; } return 0; }