結果

問題 No.807 umg tours
ユーザー 👑 jupirojupiro
提出日時 2020-03-11 18:42:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 430 ms / 4,000 ms
コード長 2,310 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 127,128 KB
実行使用メモリ 55,900 KB
最終ジャッジ日時 2024-05-03 00:13:33
合計ジャッジ時間 6,528 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,752 KB
testcase_01 AC 4 ms
10,684 KB
testcase_02 AC 5 ms
10,752 KB
testcase_03 AC 5 ms
10,752 KB
testcase_04 AC 4 ms
10,684 KB
testcase_05 AC 4 ms
10,752 KB
testcase_06 AC 5 ms
10,752 KB
testcase_07 AC 4 ms
10,752 KB
testcase_08 AC 3 ms
10,624 KB
testcase_09 AC 4 ms
10,624 KB
testcase_10 AC 3 ms
10,624 KB
testcase_11 AC 209 ms
47,276 KB
testcase_12 AC 203 ms
35,432 KB
testcase_13 AC 297 ms
46,484 KB
testcase_14 AC 112 ms
25,640 KB
testcase_15 AC 83 ms
22,472 KB
testcase_16 AC 325 ms
49,384 KB
testcase_17 AC 407 ms
55,724 KB
testcase_18 AC 415 ms
55,900 KB
testcase_19 AC 400 ms
53,576 KB
testcase_20 AC 208 ms
31,200 KB
testcase_21 AC 195 ms
31,988 KB
testcase_22 AC 69 ms
19,712 KB
testcase_23 AC 50 ms
17,536 KB
testcase_24 AC 155 ms
42,276 KB
testcase_25 AC 430 ms
54,900 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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void dijkstra(ll start, vector<pair<ll, ll>> graph[], vector<ll>& dist) {
	dist[start] = 0;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	vector<bool> used(dist.size(), false);
	pq.push(make_pair(0, start));
	while (!pq.empty()) {
		ll d, node;
		tie(d, node) = pq.top();
		pq.pop();
		if (used[node]) continue;
		used[node] = true;
		for (pair<ll, ll> element : graph[node]) {
			ll new_d, new_node;
			tie(new_node, new_d) = element;
			new_d += d;
			if (new_d < dist[new_node]) {
				dist[new_node] = new_d;
				pq.push(make_pair(dist[new_node], new_node));
			}
		}
	}
}

vector<pair<ll, ll>> g[100000];
vector<pair<ll, ll>> eg[200000];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int n, m; scanf("%d %d", &n, &m);
	for (int 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);
		eg[a].emplace_back(b, c);
		eg[b].emplace_back(a, c);
		eg[a + n].emplace_back(b + n, c);
		eg[b + n].emplace_back(a + n, c);
		eg[a].emplace_back(b + n, 0);
		eg[b].emplace_back(a + n, 0);
	}
	vector<ll> d1(n, INF);
	vector<ll> d2(n * 2, INF);
	dijkstra(0, g, d1);
	dijkstra(0, eg, d2);
	for (ll i = 0; i < n; i++) {
		printf("%lld\n", d1[i] + min(d2[i], d2[i + n]));
	}
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0