結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-01 02:04:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 292 ms / 4,000 ms |
| コード長 | 2,193 bytes |
| コンパイル時間 | 1,468 ms |
| コンパイル使用メモリ | 128,252 KB |
| 実行使用メモリ | 28,036 KB |
| 最終ジャッジ日時 | 2024-11-23 19:48:21 |
| 合計ジャッジ時間 | 5,398 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
struct Distance {
ll x, used, d;
Distance(ll _x, ll _used, ll _d) :x(_x), used(_used), d(_d) {};
bool operator< (const Distance &e)const {
return d > e.d;
}
};
bool used[100500][2];
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll n, m; scanf("%lld %lld", &n, &m);
vector<vector<pair<int, ll>>> g(n);
for (ll i = 0; i < m; i++) {
ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
a--; b--;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
vector<vector<ll>> dp(n, vector<ll>(2, INF));
dp[0][0] = 0;
dp[0][1] = 0;
priority_queue<Distance> pq;
pq.emplace(0, 0, 0);
pq.emplace(0, 1, 0);
while (!pq.empty()) {
Distance now = pq.top();
pq.pop();
if (used[now.x][now.used]) continue;
used[now.x][now.used] = true;
if (now.used == 0) {
for (auto next : g[now.x]) {
if (used[next.first][1]) continue;
if (dp[next.first][1] > now.d) {
dp[next.first][1] = now.d;
pq.emplace(next.first, 1, dp[next.first][1]);
}
}
}
for (auto next : g[now.x]) {
if (used[next.first][now.used]) continue;
if (dp[next.first][now.used] > now.d + next.second) {
dp[next.first][now.used] = now.d + next.second;
pq.emplace(next.first, now.used, dp[next.first][now.used]);
}
}
}
for (ll i = 0; i < n; i++) {
printf("%lld\n", dp[i][0] + dp[i][1]);
}
return 0;
}