結果

問題 No.807 umg tours
ユーザー rabimearabimea
提出日時 2023-01-25 20:05:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 848 ms / 4,000 ms
コード長 1,155 bytes
コンパイル時間 2,779 ms
コンパイル使用メモリ 210,332 KB
実行使用メモリ 37,512 KB
最終ジャッジ日時 2023-09-09 05:18:12
合計ジャッジ時間 12,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,112 KB
testcase_01 AC 4 ms
8,184 KB
testcase_02 AC 4 ms
8,080 KB
testcase_03 AC 4 ms
8,316 KB
testcase_04 AC 4 ms
8,052 KB
testcase_05 AC 4 ms
8,124 KB
testcase_06 AC 4 ms
8,136 KB
testcase_07 AC 4 ms
8,144 KB
testcase_08 AC 4 ms
8,084 KB
testcase_09 AC 3 ms
8,160 KB
testcase_10 AC 4 ms
8,088 KB
testcase_11 AC 286 ms
24,304 KB
testcase_12 AC 455 ms
26,168 KB
testcase_13 AC 557 ms
30,760 KB
testcase_14 AC 199 ms
18,740 KB
testcase_15 AC 140 ms
17,184 KB
testcase_16 AC 533 ms
31,988 KB
testcase_17 AC 812 ms
37,200 KB
testcase_18 AC 826 ms
37,372 KB
testcase_19 AC 746 ms
37,512 KB
testcase_20 AC 479 ms
29,480 KB
testcase_21 AC 477 ms
30,316 KB
testcase_22 AC 152 ms
17,768 KB
testcase_23 AC 113 ms
15,628 KB
testcase_24 AC 260 ms
32,424 KB
testcase_25 AC 848 ms
37,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 2e5 + 11;
vector <pii> e[N];
ll dis[N];

const ll inf = 1e18;

int main() {
	ios :: sync_with_stdio(false);
	int n, m; cin >> n >> m;
	
	for(int i = 1; i <= m; i ++) {
		int u, v, w; cin >> u >> v >> w;
		e[u].pb({v, w}); e[v].pb({u, w});
		e[u].pb({v + n, 0}); e[v].pb({u + n, 0});
		e[u + n].pb({v + n, w}); e[v + n].pb({u + n, w});
	}
	
	fill(dis, dis + n + n + 1, inf);
	set <pair <ll, int>> st;
	dis[1] = 0;
	for(int i = 1; i <= n * 2; i ++)
		st.insert({dis[i], i});
		
	while(!st.empty()) {
		int x = st.begin() -> se;
		st.erase(st.begin());
		for(auto [v, w] : e[x])
			if(dis[x] + w < dis[v]) {
				st.erase({dis[v], v});
				dis[v] = dis[x] + w;
				st.insert({dis[v], v});
			}
	}
	
	for(int i = 1; i <= n; i ++)
		cout << (i == 1 ? 0 : dis[i] + dis[i + n]) << '\n';
}
0