結果

問題 No.807 umg tours
ユーザー umezoumezo
提出日時 2022-08-09 13:49:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 664 ms / 4,000 ms
コード長 1,646 bytes
コンパイル時間 2,814 ms
コンパイル使用メモリ 213,540 KB
実行使用メモリ 57,820 KB
最終ジャッジ日時 2023-10-19 23:36:47
合計ジャッジ時間 11,463 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 323 ms
41,956 KB
testcase_12 AC 365 ms
32,868 KB
testcase_13 AC 494 ms
45,108 KB
testcase_14 AC 191 ms
21,424 KB
testcase_15 AC 152 ms
17,860 KB
testcase_16 AC 511 ms
48,324 KB
testcase_17 AC 662 ms
56,560 KB
testcase_18 AC 663 ms
56,720 KB
testcase_19 AC 655 ms
54,468 KB
testcase_20 AC 362 ms
30,508 KB
testcase_21 AC 374 ms
31,552 KB
testcase_22 AC 148 ms
15,656 KB
testcase_23 AC 110 ms
12,976 KB
testcase_24 AC 305 ms
43,052 KB
testcase_25 AC 664 ms
57,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,m;
  cin>>n>>m;
  
  Graph G(2*n),H(n);
  rep(i,m){
    int a,b;
    ll w;
    cin>>a>>b>>w;
    a--,b--;
    G[a].push_back(Edge(b,w));
    G[b].push_back(Edge(a,w));
    G[a].push_back(Edge(b+n,0));
    G[b].push_back(Edge(a+n,0));
    G[a+n].push_back(Edge(b+n,w));
    G[b+n].push_back(Edge(a+n,w));
    H[a].push_back(Edge(b,w));
    H[b].push_back(Edge(a,w));
  }
  
  vector<ll> dist(2*n,INF),dist1(n,INF);
  int s=0;
  dist[s]=0;
  dist1[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que,que1;
  que.push({dist[s],s});
  que1.push({dist1[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;

    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  
  while(!que1.empty()){
    int v=que1.top().second;
    ll d=que1.top().first;
    que1.pop();
    
    if(d>dist1[v]) continue;

    for(auto e:H[v]){
      if(chmin(dist1[e.to],dist1[v]+e.w)){
        que1.push({dist1[e.to],e.to});
      }
    }
  }
  
  cout<<0<<endl;
  for(int i=1;i<n;i++) cout<<dist[i+n]+dist1[i]<<endl;
  
  return 0;
}
0