結果

問題 No.807 umg tours
ユーザー monnumonnu
提出日時 2020-09-28 22:53:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 178,996 KB
実行使用メモリ 21,108 KB
最終ジャッジ日時 2023-09-15 15:32:30
合計ジャッジ時間 11,772 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 235 ms
14,972 KB
testcase_12 AC 194 ms
13,236 KB
testcase_13 AC 286 ms
16,976 KB
testcase_14 AC 111 ms
9,028 KB
testcase_15 AC 87 ms
8,236 KB
testcase_16 AC 313 ms
18,980 KB
testcase_17 AC 362 ms
20,900 KB
testcase_18 AC 360 ms
21,032 KB
testcase_19 AC 361 ms
21,108 KB
testcase_20 AC 183 ms
12,208 KB
testcase_21 AC 192 ms
12,664 KB
testcase_22 AC 73 ms
7,268 KB
testcase_23 AC 56 ms
6,216 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000000000
using ll=long long;
using Graph=vector<vector<pair<int,ll>>>;

int main(){
  int N,M;
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<M;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    a--;
    b--;
    G[a].push_back(make_pair(b,c));
    G[b].push_back(make_pair(a,c));
  }

  vector<ll> dist1(N,INF);
  dist1[0]=0;
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq1,pq2;
  pq1.push(make_pair(dist1[0],0));
  while(!pq1.empty()){
    int v=pq1.top().second;
    pq1.pop();
    for(auto p:G[v]){
      int nv=p.first;
      ll d=p.second;
      if(dist1[v]+d<dist1[nv]){
        dist1[nv]=dist1[v]+d;
        pq1.push(make_pair(dist1[nv],nv));
      }
    }
  }

  vector<ll> dist2=dist1;
  pq2.push(make_pair(dist2[0],0));
  while(!pq2.empty()){
    int v=pq2.top().second;
    pq2.pop();
    for(auto p:G[v]){
      int nv=p.first;
      ll d=p.second;
      if(dist2[nv]>min(dist1[v],dist2[v]+d)){
        dist2[nv]=min(dist1[v],dist2[v]+d);
        pq2.push(make_pair(dist2[nv],nv));
      }
    }
  }

  for(int i=0;i<N;i++){
    cout<<dist1[i]+dist2[i]<<'\n';
  }
}
0