結果

問題 No.807 umg tours
ユーザー spihillspihill
提出日時 2019-03-22 22:29:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 520 ms / 4,000 ms
コード長 3,632 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 189,976 KB
実行使用メモリ 24,468 KB
最終ジャッジ日時 2024-11-23 19:05:39
合計ジャッジ時間 8,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 314 ms
19,344 KB
testcase_12 AC 278 ms
14,640 KB
testcase_13 AC 386 ms
20,668 KB
testcase_14 AC 167 ms
11,580 KB
testcase_15 AC 130 ms
9,028 KB
testcase_16 AC 412 ms
18,680 KB
testcase_17 AC 507 ms
23,476 KB
testcase_18 AC 494 ms
23,524 KB
testcase_19 AC 495 ms
23,552 KB
testcase_20 AC 276 ms
12,736 KB
testcase_21 AC 289 ms
12,928 KB
testcase_22 AC 123 ms
7,552 KB
testcase_23 AC 93 ms
6,656 KB
testcase_24 AC 310 ms
21,124 KB
testcase_25 AC 520 ms
24,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using ll = long long;
#define int ll

using namespace std;

//0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
//a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
//a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
//a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
//next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v) \
	sort(all(v)); \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
	type x;          \
	cin >> x
#define YES(f) if ((f)) {cout << "YES" << endl;} else {cout << "NO" << endl;}
#define Yes(f) if ((f)) {cout << "Yes" << endl;} else {cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
//b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
//c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N)             \
	do                         \
	{                          \
		v.RS(N);               \
		rep(i, N) cin >> v[i]; \
	} while (0);

#define RCINV(v, N)             \
	do                          \
	{                           \
		v.RS(N);                \
		rrep(i, N) cin >> v[i]; \
	} while (0);
#define MOD 1000000007

template <class T>
inline T GET()
{
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, M;
vector<vector<pair<int, int>>> v;
vector<int> d[2];
#define INF LLONG_MAX

void init()
{
	cin >> N >> M;
	v.resize(N, vector<pair<int, int>>(0));
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;b--;
		v[a].push_back(MP(b, c));
		v[b].push_back(MP(a, c));
	}
	d[0].resize(N, INF);
	d[1].resize(N, INF);
	priority_queue<pair<int, pair<int, int>>> q;
	q.push(make_pair(0, make_pair(0, 0)));
	q.push(make_pair(0, make_pair(0, 1)));
	while (!q.empty()) {
		auto x = q.top();
		q.pop();
		int c = -x.first;
		int p = x.second.first;
		int k = x.second.second;
		if (d[k][p] <= c) continue;
		d[k][p] = c;
		for (auto y : v[p]) {
			if (k == 1) {
				if (c+y.second < d[1][y.first]) {
					q.push(MP(-c-y.second, MP(y.first, 1)));
				}
			} else {
				if (c+y.second < d[0][y.first]) {
					q.push(MP(-c-y.second, MP(y.first, 0)));
				}
				if (c < d[1][y.first]) {
					q.push(MP(-c, MP(y.first, 1)));
				}
			}
		}
	}
	rep(i, N) {
		cout << d[0][i] + d[1][i] << endl;
	}
}

void solve()
{
}
0