結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2019-03-22 22:14:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 341 ms / 4,000 ms |
| コード長 | 1,622 bytes |
| コンパイル時間 | 2,217 ms |
| コンパイル使用メモリ | 185,052 KB |
| 実行使用メモリ | 24,360 KB |
| 最終ジャッジ日時 | 2024-11-23 19:03:25 |
| 合計ジャッジ時間 | 7,197 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = std::int64_t;
using P = std::tuple<ll,ll>;
using T = std::tuple<ll,ll,ll>;
constexpr ll INF = std::numeric_limits<ll>::max() / 2;
int N, M;
std::vector<P> G[100100];
std::priority_queue<T, std::vector<T>, std::greater<T>> pq;
ll dist[100100][2];
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> M;
for(int i=0;i<M;++i){
int a, b, c;
std::cin >> a >> b >> c;
G[a].emplace_back(b, c);
G[b].emplace_back(a, c);
}
std::fill(&dist[0][0], &dist[0][0] + 100100 * 2, INF);
dist[1][0] = 0;
dist[1][1] = 0;
pq.emplace(0, 1, 0);
until(pq.empty()){
int v, t;
ll d;
std::tie(d, v, t) = pq.top();
pq.pop();
if(d > dist[v][t]){
continue;
}
for(auto &e : G[v]){
int w, c;
std::tie(w, c) = e;
if(d + c < dist[w][t]){
dist[w][t] = d + c;
pq.emplace(dist[w][t], w, t);
}
}
if(t == 0){
for(auto &e : G[v]){
int w;
std::tie(w, std::ignore) = e;
if(d < dist[w][1]){
dist[w][1] = d;
pq.emplace(dist[w][1], w, 1);
}
}
}
}
for(int i=1;i<=N;++i){
ll mn = dist[i][0] + dist[i][1];
std::cout << mn << std::endl;
}
}
tottoripaper