結果

問題 No.807 umg tours
ユーザー FF256grhyFF256grhy
提出日時 2019-03-22 21:50:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 524 ms / 4,000 ms
コード長 2,580 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 176,432 KB
実行使用メモリ 49,620 KB
最終ジャッジ日時 2023-08-15 11:54:41
合計ジャッジ時間 8,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,072 KB
testcase_01 AC 4 ms
8,156 KB
testcase_02 AC 4 ms
8,116 KB
testcase_03 AC 4 ms
8,156 KB
testcase_04 AC 4 ms
8,068 KB
testcase_05 AC 4 ms
8,136 KB
testcase_06 AC 4 ms
8,240 KB
testcase_07 AC 4 ms
8,172 KB
testcase_08 AC 3 ms
8,016 KB
testcase_09 AC 4 ms
8,076 KB
testcase_10 AC 4 ms
8,076 KB
testcase_11 AC 309 ms
36,884 KB
testcase_12 AC 275 ms
29,648 KB
testcase_13 AC 392 ms
38,756 KB
testcase_14 AC 158 ms
21,276 KB
testcase_15 AC 119 ms
18,576 KB
testcase_16 AC 418 ms
40,560 KB
testcase_17 AC 524 ms
46,800 KB
testcase_18 AC 517 ms
47,120 KB
testcase_19 AC 509 ms
44,536 KB
testcase_20 AC 264 ms
28,052 KB
testcase_21 AC 275 ms
28,824 KB
testcase_22 AC 106 ms
17,060 KB
testcase_23 AC 83 ms
15,264 KB
testcase_24 AC 222 ms
40,232 KB
testcase_25 AC 519 ms
49,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

template<typename T> class RPQ : public priority_queue<T, vector<T>, greater<T>> { };
template<typename C> void dijkstra(int s, vector<pair<int, C>> g[], C d[]) {
	RPQ<pair<C, int>> q;
	d[s] = 0;
	q.emplace(d[s], s);
	while(! q.empty()) {
		C   c = q.top().FI;
		int v = q.top().SE;
		q.pop();
		if(d[v] != c) { continue; }
		for(auto & e : g[v]) {
			int ev = e.FI;
			C   ec = e.SE;
			if(setmin(d[ev], d[v] + ec)) { q.emplace(d[ev], ev); }
		}
	}
}

int n, m;
vector<pair<int, LL>> g[200000];
LL d[200000];

int main() {
	cin >> n >> m;
	inc(i, m) {
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		int A = a + n, B = b + n;
		g[a].EB(b, c);
		g[b].EB(a, c);
		g[A].EB(B, c);
		g[B].EB(A, c);
		g[a].EB(B, 0);
		g[b].EB(A, 0);
	}
	inc(i, n) { g[i].EB(i + n, 0); }
	
	inc(i, 2 * n) { d[i] = 1e16; }
	dijkstra(0, g, d);
	
	inc(i, n) { cout << d[i] + d[i + n] << "\n"; }
	
	return 0;
}
0