結果

問題 No.807 umg tours
ユーザー misora192misora192
提出日時 2020-06-05 09:25:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 4,000 ms
コード長 1,542 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 177,000 KB
実行使用メモリ 42,228 KB
最終ジャッジ日時 2024-05-03 00:24:43
合計ジャッジ時間 7,022 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,192 KB
testcase_01 AC 4 ms
8,192 KB
testcase_02 AC 4 ms
8,192 KB
testcase_03 AC 5 ms
8,192 KB
testcase_04 AC 4 ms
8,104 KB
testcase_05 AC 4 ms
8,192 KB
testcase_06 AC 4 ms
8,192 KB
testcase_07 AC 3 ms
8,248 KB
testcase_08 AC 4 ms
8,064 KB
testcase_09 AC 4 ms
8,192 KB
testcase_10 AC 5 ms
8,192 KB
testcase_11 AC 198 ms
35,640 KB
testcase_12 AC 228 ms
26,152 KB
testcase_13 AC 323 ms
34,476 KB
testcase_14 AC 129 ms
19,064 KB
testcase_15 AC 105 ms
16,640 KB
testcase_16 AC 296 ms
36,428 KB
testcase_17 AC 404 ms
40,784 KB
testcase_18 AC 397 ms
41,024 KB
testcase_19 AC 378 ms
39,252 KB
testcase_20 AC 223 ms
23,040 KB
testcase_21 AC 235 ms
23,424 KB
testcase_22 AC 89 ms
14,736 KB
testcase_23 AC 68 ms
13,312 KB
testcase_24 AC 210 ms
30,320 KB
testcase_25 AC 402 ms
42,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct edge {ll to, cost;};
typedef pair<ll, ll> P; // firstはsからの最短距離, secondは頂点の番号

struct dat{
	// sからの最短距離, 今の頂点の番号
	ll dis, idx;

	bool operator<(const dat & a) const{
		return dis > a.dis;
	}
};

const ll INF = 1e17;
const int max_n = 202020;

int n;
vector<edge> g[max_n];

void dijkstra(ll s, vector<ll> &d){
	rep(i, 2 * n) d[i] = INF;
	d[s] = 0;
	d[s + n] = 0;

	priority_queue<dat> que;
	que.push({0, s});

	while(!que.empty()){
		dat p = que.top();
		que.pop();

		ll v = p.idx;
		if(d[v] < p.dis) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

		for(ll i = 0; i < g[v].size(); i++){
			edge e= g[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push({d[e.to], e.to});
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int m;
	cin >> n >> m;

	rep(i, m){
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		g[a].push_back({b, c});
		g[a].push_back({b+n, 0});
		g[a+n].push_back({b+n, c});
		g[b].push_back({a, c});
		g[b].push_back({a+n, 0});
		g[b+n].push_back({a+n, c});
	}

	vector<ll> d(2 * n);
	dijkstra(0, d);

	rep(i, n) cout << d[i] + d[i+n] << endl;
}
0