結果

問題 No.807 umg tours
ユーザー kwm_tkwm_t
提出日時 2023-04-13 21:32:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 4,000 ms
コード長 1,949 bytes
コンパイル時間 2,950 ms
コンパイル使用メモリ 208,160 KB
実行使用メモリ 29,208 KB
最終ジャッジ日時 2024-04-18 00:01:53
合計ジャッジ時間 7,182 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,320 KB
testcase_01 AC 4 ms
8,192 KB
testcase_02 AC 3 ms
8,064 KB
testcase_03 AC 3 ms
8,320 KB
testcase_04 AC 3 ms
8,288 KB
testcase_05 AC 4 ms
8,064 KB
testcase_06 AC 4 ms
8,320 KB
testcase_07 AC 4 ms
8,320 KB
testcase_08 AC 4 ms
8,292 KB
testcase_09 AC 5 ms
8,192 KB
testcase_10 AC 4 ms
8,064 KB
testcase_11 AC 132 ms
20,388 KB
testcase_12 AC 142 ms
20,404 KB
testcase_13 AC 176 ms
23,552 KB
testcase_14 AC 73 ms
15,336 KB
testcase_15 AC 70 ms
13,680 KB
testcase_16 AC 198 ms
24,320 KB
testcase_17 AC 277 ms
29,164 KB
testcase_18 AC 246 ms
29,208 KB
testcase_19 AC 245 ms
27,320 KB
testcase_20 AC 150 ms
20,480 KB
testcase_21 AC 139 ms
21,120 KB
testcase_22 AC 54 ms
13,780 KB
testcase_23 AC 36 ms
12,416 KB
testcase_24 AC 99 ms
26,160 KB
testcase_25 AC 266 ms
28,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
	int to;
	long long cost;
	Edge(int _to, long long _cost) :to(_to), cost(_cost) {}
};
vector<Edge>g[200005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<vector<Edge>>g(n);
	rep(i, m) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}

	priority_queue<pair<long long, P>, vector<pair<long long, P>>, greater<pair<long long, P>>> q;
	q.push({ 0,{0,0} });
	q.push({ 0,{0,1} });
	vector<vector<long long>>dp(n, vector<long long>(2, LINF));
	dp[0][0] = 0;
	dp[0][1] = 0;
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		long long cost = tmp.first;
		int pos = tmp.second.first;
		int cnt = tmp.second.second;
		if (cost > dp[pos][cnt]) continue;
		for (Edge e : g[pos]) {
			rep(i, 2) {
				long long ncost = cost;
				if (0 == i)ncost += e.cost;
				int npos = e.to;
				int ncnt = cnt + i;
				if (ncnt >= 2)continue;
				if (chmin(dp[npos][ncnt], ncost)) q.push({ ncost, {npos,ncnt} });
			}
		}
	}
	rep(i, n) {
		long long ans = dp[i][0] + dp[i][1];
		cout << ans << endl;
	}
	return 0;
}
0