結果
問題 | No.807 umg tours |
ユーザー | matsukin1111 |
提出日時 | 2019-05-04 12:19:41 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 509 ms / 4,000 ms |
コード長 | 1,764 bytes |
コンパイル時間 | 1,129 ms |
コンパイル使用メモリ | 108,348 KB |
実行使用メモリ | 25,192 KB |
最終ジャッジ日時 | 2023-08-15 12:22:56 |
合計ジャッジ時間 | 7,897 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,732 KB |
testcase_01 | AC | 3 ms
5,816 KB |
testcase_02 | AC | 4 ms
5,840 KB |
testcase_03 | AC | 4 ms
5,812 KB |
testcase_04 | AC | 4 ms
6,020 KB |
testcase_05 | AC | 4 ms
5,792 KB |
testcase_06 | AC | 4 ms
6,052 KB |
testcase_07 | AC | 4 ms
5,752 KB |
testcase_08 | AC | 3 ms
5,736 KB |
testcase_09 | AC | 3 ms
5,712 KB |
testcase_10 | AC | 4 ms
5,756 KB |
testcase_11 | AC | 278 ms
19,008 KB |
testcase_12 | AC | 285 ms
15,608 KB |
testcase_13 | AC | 380 ms
18,636 KB |
testcase_14 | AC | 161 ms
11,432 KB |
testcase_15 | AC | 126 ms
9,864 KB |
testcase_16 | AC | 383 ms
20,232 KB |
testcase_17 | AC | 503 ms
24,048 KB |
testcase_18 | AC | 509 ms
24,324 KB |
testcase_19 | AC | 487 ms
20,116 KB |
testcase_20 | AC | 296 ms
12,896 KB |
testcase_21 | AC | 302 ms
13,100 KB |
testcase_22 | AC | 128 ms
8,824 KB |
testcase_23 | AC | 99 ms
8,136 KB |
testcase_24 | AC | 311 ms
20,780 KB |
testcase_25 | AC | 501 ms
25,192 KB |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include <cstdlib> #include <math.h> #include <cmath> #include<cctype> #include<string> #include<set> #include<iomanip> #include <map> #include<algorithm> #include <functional> #include<vector> #include<climits> #include<stack> #include<queue> #include <deque> #include <climits> #include <typeinfo> #include <utility> #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair<ll, vector<int>>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; typedef tuple<ll, ll, ll>T; int n, m; vector<pair<ll, ll>>E[101010]; void dijkstra(int n,int m,vector<vector<ll>> &dp) { dp[0][0] = 0; dp[1][0] = 0; priority_queue<T,vector<T>,greater<T>>Q; Q.push({0,0,0}); Q.push({0,1,0}); while (!Q.empty()) { auto t = Q.top(); Q.pop(); ll cost = get<0>(t); ll state = get<1>(t); ll v = get<2>(t); if (cost > dp[state][v])continue; rep(i, 0, E[v].size()) { auto &e = E[v][i]; if (dp[state][e.first] > cost + e.second) { dp[state][e.first] = cost + e.second; Q.push({dp[state][e.first],state,e.first}); } if (state == 0) { if (dp[1][e.first] > cost) { dp[1][e.first] = cost; Q.push({dp[1][e.first],1,e.first}); } } } } } int main() { cin >> n >> m; rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; a--, b--; E[a].pb({b,c}); E[b].pb({a,c}); } vector<vector<ll>>dp(2,vector<ll>(n,inf)); dijkstra(n, m, dp); rep(i, 0, n) { cout << dp[0][i] + dp[1][i] << endl; } return 0; }