結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-10-31 21:46:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,325 bytes
コンパイル時間 3,530 ms
コンパイル使用メモリ 227,068 KB
実行使用メモリ 35,792 KB
最終ジャッジ日時 2023-10-13 00:13:44
合計ジャッジ時間 9,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,704 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

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

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