結果

問題 No.807 umg tours
ユーザー treeonetreeone
提出日時 2019-03-22 21:35:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 4,000 ms
コード長 1,607 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 208,604 KB
実行使用メモリ 24,316 KB
最終ジャッジ日時 2023-08-15 11:50:49
合計ジャッジ時間 6,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,912 KB
testcase_01 AC 2 ms
5,664 KB
testcase_02 AC 3 ms
5,996 KB
testcase_03 AC 3 ms
5,968 KB
testcase_04 AC 2 ms
5,656 KB
testcase_05 AC 3 ms
5,660 KB
testcase_06 AC 3 ms
5,720 KB
testcase_07 AC 3 ms
5,728 KB
testcase_08 AC 3 ms
5,888 KB
testcase_09 AC 3 ms
5,800 KB
testcase_10 AC 3 ms
5,704 KB
testcase_11 AC 147 ms
17,696 KB
testcase_12 AC 185 ms
15,796 KB
testcase_13 AC 231 ms
17,872 KB
testcase_14 AC 102 ms
11,208 KB
testcase_15 AC 79 ms
9,624 KB
testcase_16 AC 252 ms
18,936 KB
testcase_17 AC 317 ms
24,184 KB
testcase_18 AC 317 ms
24,232 KB
testcase_19 AC 310 ms
20,032 KB
testcase_20 AC 185 ms
12,592 KB
testcase_21 AC 195 ms
12,844 KB
testcase_22 AC 82 ms
8,904 KB
testcase_23 AC 64 ms
7,872 KB
testcase_24 AC 193 ms
18,672 KB
testcase_25 AC 324 ms
24,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m;
const int MAX_V = 100010;

struct edge{
   int to, cost;
   edge(int to, int cost):to(to), cost(cost){}
};

struct S{
	int cost, to;
	bool flag;
	S(int cost, int to, bool flag):cost(cost), to(to), flag(flag){}
	bool operator>(const S &s) const{
		return cost > s.cost;
	}
};

vector<edge> G[MAX_V];

struct Dijkstra{
	vector<int> d, e;
	Dijkstra(){}
	Dijkstra(int V){
		d.resize(V, INF);
		e.resize(V, INF);
	}
	void calc(int s){
		d[s] = 0;
		e[s] = 0;
		priority_queue<S, vector<S>, greater<S> > q;
		q.push({d[s], s, false});
		while(!q.empty()){
			S p = q.top(); q.pop();
			int from = p.to;
			int cost = p.cost;
			bool f = p.flag;
			if(d[from] < cost) continue;
			rep(i, 0, G[from].size()){
				int next = G[from][i].to;
				int newCost = cost + G[from][i].cost;
				if(f == false){
					if(d[next] > newCost){
						d[next] = newCost;
						q.push({newCost, next, f});
					}
					if(e[next] > cost){
						e[next] = cost;
						q.push({cost, next, true});
					}
				}else{
					if(e[next] > newCost){
						e[next] = newCost;
						q.push({newCost, next, f});
					}
				}
			}
		}
	}
};

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i, 0, m){
		int u, v, c;
		cin >> u >> v >> c;
		u--; v--;
		G[u].push_back({v, c});
		G[v].push_back({u, c});
	}
	Dijkstra ds(n);
	ds.calc(0);
	rep(i, 0, n){
		int ans = ds.d[i] + ds.e[i];
		cout << ans << endl;
	}
}
0