結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-03-16 22:45:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 258 ms / 4,000 ms |
| コード長 | 1,961 bytes |
| コンパイル時間 | 2,330 ms |
| コンパイル使用メモリ | 195,832 KB |
| 実行使用メモリ | 24,488 KB |
| 最終ジャッジ日時 | 2024-11-23 19:52:32 |
| 合計ジャッジ時間 | 6,088 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T>
struct edge {
int src,to;
T cost;
edge() = default;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
bool operator<(const edge &e) const {
return cost < e.cost;
}
};
ll dist[101010][2];
using Tu = tuple<ll, ll, ll>;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<vector<edge<ll>>> G(N);
rep(i,M) {
int a,b,c; cin >> a >> b >> c;
--a; --b;
G[a].emplace_back(b,c);
G[b].emplace_back(a,c);
}
priority_queue<Tu, vector<Tu>, greater<Tu>> pq;
pq.emplace(make_tuple(0,0,0));
rep(i,N) rep(j,2) dist[i][j] = 1e18;
dist[0][0] = dist[0][1] = 0;
while (!pq.empty()) {
ll d,v,n;
tie(d,v,n) = pq.top(); pq.pop();
if (d > dist[v][n]) continue;
for (auto &e : G[v]) {
if (chmin(dist[e.to][n],dist[v][n] + e.cost)) {
pq.emplace(make_tuple(dist[e.to][n],e.to,n));
}
if (n == 0 && chmin(dist[e.to][1],dist[v][0])) {
pq.emplace(make_tuple(dist[e.to][1],e.to,1));
}
}
}
rep(i,N) {
cout << dist[i][0] + dist[i][1] << ln;
}
}
minato