結果

問題 No.807 umg tours
ユーザー beetbeet
提出日時 2019-03-22 21:31:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 4,000 ms
コード長 1,429 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 209,152 KB
実行使用メモリ 49,940 KB
最終ジャッジ日時 2023-08-15 11:50:07
合計ジャッジ時間 8,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 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,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 209 ms
34,156 KB
testcase_12 AC 220 ms
29,148 KB
testcase_13 AC 305 ms
38,328 KB
testcase_14 AC 119 ms
18,912 KB
testcase_15 AC 83 ms
16,028 KB
testcase_16 AC 319 ms
40,628 KB
testcase_17 AC 433 ms
48,084 KB
testcase_18 AC 399 ms
48,508 KB
testcase_19 AC 399 ms
46,236 KB
testcase_20 AC 220 ms
29,220 KB
testcase_21 AC 229 ms
30,320 KB
testcase_22 AC 83 ms
15,044 KB
testcase_23 AC 60 ms
12,456 KB
testcase_24 AC 150 ms
42,204 KB
testcase_25 AC 396 ms
49,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){  
  const T INF = numeric_limits<T>::max();    
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  using P = pair<Int, Int>;
  vector<vector<P> > G(n*2);
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
    
    G[a+n].emplace_back(b+n,c);
    G[b+n].emplace_back(a+n,c);

    G[a].emplace_back(b+n,0);
    G[b].emplace_back(a+n,0);
  }
  for(Int i=0;i<n;i++) G[i].emplace_back(i+n,0);
  auto d=dijkstra(0,G);
  
  for(Int i=0;i<n;i++)
    cout<<d[i]+d[i+n]<<"\n";
  cout<<flush;
  return 0;
}
0