結果

問題 No.807 umg tours
ユーザー gazellegazelle
提出日時 2019-03-22 21:34:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 4,000 ms
コード長 1,655 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 131,336 KB
実行使用メモリ 27,752 KB
最終ジャッジ日時 2024-05-02 23:16:32
合計ジャッジ時間 7,821 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 187 ms
16,600 KB
testcase_12 AC 227 ms
16,752 KB
testcase_13 AC 304 ms
19,816 KB
testcase_14 AC 138 ms
11,032 KB
testcase_15 AC 100 ms
9,188 KB
testcase_16 AC 327 ms
20,772 KB
testcase_17 AC 436 ms
26,736 KB
testcase_18 AC 417 ms
26,808 KB
testcase_19 AC 437 ms
23,648 KB
testcase_20 AC 258 ms
16,212 KB
testcase_21 AC 304 ms
16,640 KB
testcase_22 AC 116 ms
9,216 KB
testcase_23 AC 85 ms
7,680 KB
testcase_24 AC 242 ms
25,048 KB
testcase_25 AC 467 ms
27,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<pll>> g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].pb({b, c});
		g[b].pb({a, c});
	}
	vector<vector<ll>> dir(n, vector<ll>(2, INF * INF));
	dir[0][0] = 0;
	priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> q;
	q.push({0, {0, 0}});
	while(!q.empty()) {
		ll c = q.top().first;
		ll p = q.top().second.first, d = q.top().second.second;
		q.pop();
		if(dir[p][d] != c) continue;
		REP(i, g[p].size()) {
			ll np = g[p][i].first, cost = g[p][i].second;
			if(dir[np][d] > c + cost) {
				dir[np][d] = c + cost;
				q.push({dir[np][d], {np, d}});
			}
			if(d == 0 && dir[np][1] > c) {
				dir[np][1] = c;
				q.push({dir[np][1], {np, 1}});
			}
		}
	}
	REP(i, n) {
		if(i == 0) {
			cout << 0 << endl;
		} else {
			cout << dir[i][0] + dir[i][1] << endl;
		}
	}
	return 0;
}

/* --------------------------------------- */
0