結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2021-05-13 23:24:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 664 ms / 4,000 ms |
コード長 | 1,519 bytes |
コンパイル時間 | 856 ms |
コンパイル使用メモリ | 81,864 KB |
実行使用メモリ | 30,392 KB |
最終ジャッジ日時 | 2024-09-25 11:16:23 |
合計ジャッジ時間 | 8,791 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <iostream> #include <vector> #include <queue> using namespace std; using ll = long long int; constexpr ll INF = 1LL << 60; struct Node{ int to; ll cost; int isused; bool operator>(const Node &other) const { if(this->cost != other.cost) return this->cost > other.cost; else return this->isused > other.isused; } }; int main(){ int n, m; cin >> n >> m; vector<vector<Node>> G(n); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c, 0}); G[b].push_back({a, c, 0}); } vector<vector<ll>> dist(n, vector<ll>(2, INF)); dist[0][0] = 0; dist[0][1] = 0; priority_queue<Node, vector<Node>, greater<Node>> Q; Q.push({0, 0, 0}); while(Q.size()){ auto ccur = Q.top(); Q.pop(); int cur = ccur.to; ll ccost = ccur.cost; int isused = ccur.isused; if(ccost > dist[cur][isused]) continue; for(auto &p: G[cur]){ if(isused == 0 && dist[p.to][1] > dist[cur][isused]){ dist[p.to][1] = dist[cur][isused]; Q.push({p.to, dist[p.to][1], 1}); } if(dist[p.to][isused] > dist[cur][isused] + p.cost){ dist[p.to][isused] = dist[cur][isused] + p.cost; Q.push({p.to, dist[p.to][isused], isused}); } } } for(int i = 0; i < n; i++){ cout << dist[i][0] + dist[i][1] << endl; } return 0; }