結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
kya_ski
|
| 提出日時 | 2019-10-26 18:49:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,664 bytes |
| コンパイル時間 | 1,866 ms |
| コンパイル使用メモリ | 182,840 KB |
| 実行使用メモリ | 57,224 KB |
| 最終ジャッジ日時 | 2024-09-14 15:54:44 |
| 合計ジャッジ時間 | 9,980 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}
const long long INF = 1e12;
vector<long long> dijkstra(const Graph &g, int s) {
vector<long long> dist(g.size(), INF);
using Pi = pair<long long, int>;
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
dist[s] = 0; que.emplace(dist[s], s);
while (!que.empty()) {
long long cost; int u; tie(cost, u) = que.top(); que.pop();
if (dist[u] < cost) continue;
for (auto &e: g[u]) {
int v; long long nc; tie(v, nc) = e;
if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
}
}
return dist;
}
int main(){
int N, M;
cin >> N >> M;
Graph G(N, vector<edge>());
Graph H(2 * N, vector<edge>());
for (int i = 0; i < M; i++) {
int a, b;
long long c;
cin >> a >> b >> c;
a--;
b--;
G[a].push_back(make_pair(b, c));
G[b].push_back(make_pair(a, c));
H[a].push_back(make_pair(b, c));
H[b].push_back(make_pair(a, c));
H[N + a].push_back(make_pair(N + b, c));
H[N + b].push_back(make_pair(N + a, c));
if(b != 0)H[a].push_back(make_pair(N + b, 0LL));
if(a != 0)H[b].push_back(make_pair(N + a, 0LL));
}
vector<long long> time2 = dijkstra(H, 0);
for (int i = 0; i < N; i++) {
cout << time2[i] + time2[i + N] << endl;
}
return 0;
}
kya_ski