結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-03-22 21:51:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,279 bytes |
| コンパイル時間 | 1,701 ms |
| コンパイル使用メモリ | 183,876 KB |
| 実行使用メモリ | 16,004 KB |
| 最終ジャッジ日時 | 2024-09-19 05:13:28 |
| 合計ジャッジ時間 | 4,685 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
struct Edge { int to, cost; };
template<class T, class Edge> pair< V<T>, V<T> > dijkstra(const VV<Edge>& g, int s = 0) {
V<T> dist(g.size(), numeric_limits<T>::max());
using P = pair<T, int>;
priority_queue< P, V<P>, greater<P> > pque;
pque.emplace(dist[s] = 0, s);
while (!pque.empty()) {
T d; int v;
tie(d, v) = pque.top(); pque.pop();
if (d > dist[v]) continue;
for (const auto& e : g[v]) if (dist[v] + e.cost < dist[e.to]) {
pque.emplace(dist[e.to] = dist[v] + e.cost, e.to);
}
}
V<T> dp(g.size(), numeric_limits<T>::max());
dp[s] = 0;
for (int v = 0; v < g.size(); ++v) {
for (const auto& e : g[v]) {
dp[e.to] = min({dp[e.to], dp[v] + e.cost, dist[v], dist[e.to]});
}
}
return {dist, dp};
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n, m; cin >> n >> m;
VV<Edge> g(n);
while (m--) {
int a, b, c; cin >> a >> b >> c, --a, --b;
g[a].emplace_back(Edge{b, c});
g[b].emplace_back(Edge{a, c});
}
auto p = dijkstra<lint>(g);
for (int i = 0; i < n; ++i) {
cout << p.first[i] + p.second[i] << '\n';
}
}
risujiroh