結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-10-31 21:50:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 4,000 ms
コード長 2,071 bytes
コンパイル時間 3,174 ms
コンパイル使用メモリ 229,000 KB
実行使用メモリ 45,376 KB
最終ジャッジ日時 2023-08-15 12:36:16
合計ジャッジ時間 9,185 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,388 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 201 ms
32,604 KB
testcase_12 AC 227 ms
27,056 KB
testcase_13 AC 312 ms
36,788 KB
testcase_14 AC 129 ms
17,612 KB
testcase_15 AC 106 ms
14,496 KB
testcase_16 AC 345 ms
37,452 KB
testcase_17 AC 425 ms
45,264 KB
testcase_18 AC 425 ms
45,376 KB
testcase_19 AC 424 ms
43,192 KB
testcase_20 AC 271 ms
23,812 KB
testcase_21 AC 280 ms
25,308 KB
testcase_22 AC 114 ms
12,776 KB
testcase_23 AC 91 ms
10,684 KB
testcase_24 AC 226 ms
33,620 KB
testcase_25 AC 411 ms
44,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct edge {
	ll to;
	ll cost;
};
typedef pair < ll, ll > P;

//基数ヒープ
template<typename T > class RadixHeapInt64 {
private:
	vector< pair<ull, T> > v[65];
	ll last, size;
	int bsr(ull x) {
		if (x == 0)return -1;
		return 64 - __builtin_clzll(x);
	}
public:
	RadixHeapInt64() {
		last = size = 0;
	}
	bool empty() {
		return size == 0;
	}
	//p = {priority,value}
	void push(ull priority, const T& value) {
		size++;
		v[bsr(priority ^ last) + 1].emplace_back(priority, value);
	}
	pair<ull, T> pop() {
		if (!v[0].size()) {
			int i = 1;
			while (!v[i].size())i++;
			last = (*min_element(v[i].begin(), v[i].end())).first;
			for (int j = 0; j < v[i].size(); j++) {
				v[bsr(v[i][j].first ^ last) + 1].push_back(v[i][j]);
			}
			v[i].clear();
		}
		size--;
		auto ret = v[0].back();
		v[0].pop_back();
		return ret;
	}
};

void dijkstra(int s, vector<vector<edge>>& g, vector<ll>& d) {
	RadixHeapInt64<ll> q;
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	q.push(0, s);

	while (!q.empty()) {
		P p = q.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(d[e.to], e.to);
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<vector<edge>> g(N*2);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
		g[a].push_back({ b + N,0 });
		g[b].push_back({ a + N,0 });
		g[a + N].push_back({ b + N,c });
		g[b + N].push_back({ a + N,c });
	}
	vector<ll> d(N * 2);
	dijkstra(0, g, d);
	for (int i = 0; i < N; i++) {
		cout << min(d[i] + d[i + N], d[i] * 2) << endl;
	}
}
0