結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
kya_ski
|
| 提出日時 | 2019-10-26 18:53:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 720 ms / 4,000 ms |
| コード長 | 1,808 bytes |
| コンパイル時間 | 2,025 ms |
| コンパイル使用メモリ | 184,920 KB |
| 実行使用メモリ | 57,184 KB |
| 最終ジャッジ日時 | 2024-11-23 19:42:32 |
| 合計ジャッジ時間 | 9,919 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 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--;
if(b != 0)G[a].push_back(make_pair(b, c));
if(a != 0)G[b].push_back(make_pair(a, c));
if(b != 0)H[a].push_back(make_pair(b, c));
if(a != 0)H[b].push_back(make_pair(a, c));
if(b != 0)H[N + a].push_back(make_pair(N + b, c));
if(a != 0)H[N + b].push_back(make_pair(N + a, c));
if(a != 0)H[b].push_back(make_pair(N + a, 0));
if(b != 0)H[a].push_back(make_pair(N + b, 0));
}
vector<long long> time1 = dijkstra(G, 0);
vector<long long> time2 = dijkstra(H, 0);
for (int i = 0; i < N; i++) {
if(i == 0)cout << 0 << endl;
else cout << time1[i] + time2[i + N] << endl;
}
return 0;
}
kya_ski