結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-10-31 21:54:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,056 bytes
コンパイル時間 3,592 ms
コンパイル使用メモリ 226,956 KB
実行使用メモリ 28,796 KB
最終ジャッジ日時 2023-10-13 00:14:03
合計ジャッジ時間 10,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 207 ms
19,188 KB
testcase_12 AC 233 ms
17,632 KB
testcase_13 AC 320 ms
23,040 KB
testcase_14 AC 126 ms
11,984 KB
testcase_15 AC 104 ms
10,188 KB
testcase_16 AC 341 ms
23,300 KB
testcase_17 AC 422 ms
28,344 KB
testcase_18 AC 429 ms
28,796 KB
testcase_19 AC 428 ms
27,372 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 220 ms
23,036 KB
testcase_25 AC 414 ms
27,740 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 {
	int to;
	int cost;
};
typedef pair<int, int> P;
vector<int> d;

template<typename T > class RadixHeapInt32 {
private:
	using uint = unsigned;
	vector< pair<uint, T> > v[33];
	ll last, size;
	int bsr(uint x) {
		if (x == 0)return -1;
		return 32 - __builtin_clz(x);
	}
public:
	RadixHeapInt32() {
		last = size = 0;
	}
	bool empty() {
		return size == 0;
	}
	//p = {priority,value}
	void push(uint priority, const T& value) {
		size++;
		v[bsr(priority ^ last) + 1].emplace_back(priority, value);
	}
	pair<uint, 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) {
	RadixHeapInt32<int> q;
	d = vector<int>(g.size(), INF);
	d[s] = 0;
	q.push(0, s);

	while (!q.empty()) {
		P p = q.pop();
		int 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 });
	}

	dijkstra(0, g);
	for (int i = 0; i < N; i++) {
		cout << min(d[i] + d[i + N], d[i] * 2) << endl;
	}
}
0