結果

問題 No.807 umg tours
ユーザー Tlapesium
提出日時 2019-10-31 21:49:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 596 ms / 4,000 ms
コード長 1,337 bytes
コンパイル時間 14,193 ms
コンパイル使用メモリ 286,836 KB
最終ジャッジ日時 2025-01-08 02:12:16
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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 <P, vector<P>, greater<P>> 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