結果

問題 No.807 umg tours
ユーザー ゆにぽけゆにぽけ
提出日時 2024-01-03 14:38:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 4,000 ms
コード長 1,487 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 142,564 KB
実行使用メモリ 22,332 KB
最終ジャッジ日時 2024-01-03 14:39:01
合計ジャッジ時間 8,413 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 163 ms
12,056 KB
testcase_12 AC 180 ms
13,908 KB
testcase_13 AC 206 ms
15,760 KB
testcase_14 AC 78 ms
9,376 KB
testcase_15 AC 55 ms
8,064 KB
testcase_16 AC 209 ms
16,108 KB
testcase_17 AC 285 ms
22,324 KB
testcase_18 AC 319 ms
22,332 KB
testcase_19 AC 271 ms
18,956 KB
testcase_20 AC 151 ms
14,716 KB
testcase_21 AC 156 ms
15,104 KB
testcase_22 AC 52 ms
8,448 KB
testcase_23 AC 40 ms
7,296 KB
testcase_24 AC 127 ms
17,592 KB
testcase_25 AC 300 ms
20,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void solve()
{
	int N,M;
	cin >> N >> M;
	vector<vector<pair<int,int>>> G(N);
	for(int i = 0;i < M;i++)
	{
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(make_pair(v,w));
		G[v].push_back(make_pair(u,w));
	}
	vector<vector<long long>> dp(N,vector<long long>(2,(long long)1e18));
	dp[0][0] = 0;
	dp[0][1] = 0;
	priority_queue<pair<long long,pair<int,int>>> Q;
	Q.push(make_pair(-0ll,make_pair(0,0)));
	while(!Q.empty())
	{
		long long cur = -Q.top().first;
		const auto [u,s] = Q.top().second;
		Q.pop();
		if(dp[u][s] < cur) continue;
		for(const auto &[v,w] : G[u])
		{
			if(dp[v][s] > dp[u][s] + w)
			{
				dp[v][s] = dp[u][s] + w;
				Q.push(make_pair(-dp[v][s],make_pair(v,s)));
			}

			if(!s)
			{
				if(dp[v][1] > dp[u][s])
				{
					dp[v][1] = dp[u][s];
					Q.push(make_pair(-dp[v][1],make_pair(v,1)));
				}
			}
		}
	}
	for(int i = 0;i < N;i++) cout << dp[i][0] + dp[i][1] << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}

0