結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:49:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,312 bytes |
コンパイル時間 | 885 ms |
コンパイル使用メモリ | 80,640 KB |
実行使用メモリ | 41,636 KB |
最終ジャッジ日時 | 2024-09-19 04:06:24 |
合計ジャッジ時間 | 9,325 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 20 TLE * 1 -- * 1 |
ソースコード
#include <queue>#include <vector>#include <iostream>using namespace std;const long long inf = 1LL << 61;struct edge {int to; long long cost;};struct state {int pos; long long cost;};bool operator<(const state& s1, const state& s2) {return s1.cost > s2.cost;}vector<long long> shortest_path(int src, vector<vector<edge> > &G) {int N = G.size();vector<long long> dist(N, inf);dist[src] = 0;priority_queue<state> que; que.push(state{ src, 0 });while (!que.empty()) {int u = que.top().pos; que.pop();for (edge e : G[u]) {if (dist[e.to] > dist[u] + e.cost) {dist[e.to] = dist[u] + e.cost;que.push(state{ e.to, dist[e.to] });}}}return dist;}int main() {cin.tie(0);ios_base::sync_with_stdio(false);int N, M;cin >> N >> M;vector<vector<edge> > G(2 * N);for (int i = 0; i < M; ++i) {int A, B, C;cin >> A >> B >> C; --A, --B;G[A].push_back(edge{ B, C });G[A + N].push_back(edge{ B + N, C });G[A].push_back(edge{ B + N, 0 });G[B].push_back(edge{ A, C });G[B + N].push_back(edge{ A + N, C });G[B].push_back(edge{ B + N, 0 });}vector<long long> d = shortest_path(0, G);for (int i = 0; i < N; ++i) {long long ans = inf;ans = min(ans, d[i] * 2);ans = min(ans, d[i] + d[i + N]);cout << ans << '\n';}return 0;}