結果

問題 No.807 umg tours
ユーザー chocobochocobo
提出日時 2019-03-22 21:53:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 596 ms / 4,000 ms
コード長 1,578 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 28,636 KB
最終ジャッジ日時 2023-08-15 11:55:52
合計ジャッジ時間 8,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 296 ms
17,388 KB
testcase_12 AC 328 ms
17,260 KB
testcase_13 AC 441 ms
20,012 KB
testcase_14 AC 187 ms
10,916 KB
testcase_15 AC 140 ms
9,124 KB
testcase_16 AC 463 ms
21,388 KB
testcase_17 AC 589 ms
28,040 KB
testcase_18 AC 596 ms
27,144 KB
testcase_19 AC 580 ms
23,372 KB
testcase_20 AC 342 ms
16,016 KB
testcase_21 AC 361 ms
16,632 KB
testcase_22 AC 141 ms
9,204 KB
testcase_23 AC 106 ms
7,616 KB
testcase_24 AC 304 ms
25,100 KB
testcase_25 AC 586 ms
28,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




using P = pair<ll, ll>;
using T = pair<ll, pair<ll, ll>>;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<vector<P>> g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b, c });
		g[b].push_back({ a, c });
	}

	vector<vector<ll>> dist(n, vector<ll>(2, INF));
	dist[0][0] = dist[0][1] = 0;
	priority_queue<T, vector<T>, greater<T>> que;
	que.push({ 0, {0, 0} });
	while (!que.empty()) {
		auto tmp = que.top(); que.pop();
		ll now = tmp.second.first, d = tmp.first, f = tmp.second.second;
		if (dist[now][f] < d) continue;
		for (auto &e : g[now]) {
			ll v = e.first, c = e.second;
			if (f == 0) {
				if (dist[v][0] > d + c) {
					dist[v][0] = d + c;
					que.push({ d + c, {v, 0} });
				}
				if (dist[v][1] > d) {
					dist[v][1] = d;
					que.push({ d, {v, 1} });
				}
			}
			else {
				if (dist[v][1] > d + c) {
					dist[v][1] = d + c;
					que.push({ d + c, {v, 1} });
				}
			}
		}
	}
	/*
	REP(i, n) {
		cout << dist[i][0] << " " << dist[i][1] << endl;
	}
	*/
	REP(i, n) {
		cout << dist[i][0] + dist[i][1] << endl;
	}
}
0