結果

問題 No.807 umg tours
ユーザー a0171610a0171610
提出日時 2020-05-18 21:27:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 4,000 ms
コード長 1,142 bytes
コンパイル時間 3,539 ms
コンパイル使用メモリ 186,720 KB
実行使用メモリ 25,908 KB
最終ジャッジ日時 2023-08-15 12:50:54
合計ジャッジ時間 8,910 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 241 ms
16,036 KB
testcase_12 AC 258 ms
15,124 KB
testcase_13 AC 336 ms
18,220 KB
testcase_14 AC 143 ms
10,004 KB
testcase_15 AC 110 ms
8,324 KB
testcase_16 AC 331 ms
18,620 KB
testcase_17 AC 426 ms
23,460 KB
testcase_18 AC 433 ms
24,672 KB
testcase_19 AC 399 ms
20,008 KB
testcase_20 AC 246 ms
12,592 KB
testcase_21 AC 261 ms
13,036 KB
testcase_22 AC 108 ms
7,696 KB
testcase_23 AC 83 ms
6,312 KB
testcase_24 AC 290 ms
21,380 KB
testcase_25 AC 419 ms
25,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint n, m;
typedef tuple<lint, lint, lint> P;
struct edge{lint to, cost;};
vector<vector<edge> > G;
vector<vector<lint> > dist;
const lint INF= 1e18;

void dij(int start){
  priority_queue<P, vector<P>, greater<P> > que;
  dist[0][0] = 0; dist[1][0] = 0;
  que.push(P(0, start, 0));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int d = get<0>(p), u = get<1>(p), flag = get<2>(p);
    if(dist[flag][u] < d) continue;
    for(auto e : G[u]){
      if(dist[flag][e.to] > dist[flag][u] + e.cost){
        dist[flag][e.to] = dist[flag][u] + e.cost;
        que.push( {dist[flag][e.to], e.to, flag} );
      }
      if(flag == 0 && dist[1][e.to] > dist[0][u]){
        dist[1][e.to] = dist[0][u];
        que.push( {dist[1][e.to], e.to, 1} );
      }
    }
  }
}

signed main(){
	cin >> n >> m;
	G.resize(n);
	dist.resize(2, vector<lint> (n, INF));
	for(int i = 0; i < m; i++){
		lint a, b, c; cin >> a >> b >> c; --a; --b;
		G[a].push_back(edge{b, c}); G[b].push_back(edge{a, c});
	}
	dij(0);
	for(int i = 0; i < n; i++) cout << dist[0][i] + dist[1][i] << endl;
}
0