結果

問題 No.807 umg tours
ユーザー 👑 jupirojupiro
提出日時 2020-02-01 02:04:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 4,000 ms
コード長 2,193 bytes
コンパイル時間 1,372 ms
コンパイル使用メモリ 127,868 KB
実行使用メモリ 28,160 KB
最終ジャッジ日時 2024-05-03 00:09:26
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 160 ms
16,888 KB
testcase_12 AC 183 ms
17,108 KB
testcase_13 AC 260 ms
20,224 KB
testcase_14 AC 93 ms
11,332 KB
testcase_15 AC 63 ms
9,472 KB
testcase_16 AC 259 ms
21,020 KB
testcase_17 AC 351 ms
27,068 KB
testcase_18 AC 356 ms
27,236 KB
testcase_19 AC 339 ms
24,072 KB
testcase_20 AC 165 ms
16,368 KB
testcase_21 AC 169 ms
16,856 KB
testcase_22 AC 54 ms
9,344 KB
testcase_23 AC 38 ms
8,064 KB
testcase_24 AC 111 ms
22,012 KB
testcase_25 AC 358 ms
28,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0