結果

問題 No.807 umg tours
ユーザー monnumonnu
提出日時 2020-09-28 23:15:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 401 ms / 4,000 ms
コード長 1,113 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 178,376 KB
実行使用メモリ 44,248 KB
最終ジャッジ日時 2023-09-15 16:15:33
合計ジャッジ時間 7,472 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 204 ms
32,052 KB
testcase_12 AC 195 ms
24,348 KB
testcase_13 AC 298 ms
32,924 KB
testcase_14 AC 108 ms
15,848 KB
testcase_15 AC 78 ms
13,580 KB
testcase_16 AC 308 ms
35,004 KB
testcase_17 AC 401 ms
42,620 KB
testcase_18 AC 381 ms
41,636 KB
testcase_19 AC 374 ms
39,016 KB
testcase_20 AC 184 ms
22,556 KB
testcase_21 AC 190 ms
23,296 KB
testcase_22 AC 69 ms
11,884 KB
testcase_23 AC 52 ms
10,032 KB
testcase_24 AC 136 ms
33,488 KB
testcase_25 AC 398 ms
44,248 KB
権限があれば一括ダウンロードができます

ソースコード

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;
  scanf("%d %d",&N,&M);
  Graph G(2*N);
  for(int i=0;i<M;i++){
    int a,b;
    ll c;
    scanf("%d %d %lld",&a,&b,&c);
    a--;
    b--;
    G[a].push_back(make_pair(b,c));
    G[b].push_back(make_pair(a,c));
    G[a+N].push_back(make_pair(b+N,c));
    G[b+N].push_back(make_pair(a+N,c));
    G[a].push_back(make_pair(b+N,0));
    G[b].push_back(make_pair(a+N,0));
  }

  vector<ll> dist1(2*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()){
    pair<ll,int> p=pq1.top();
    pq1.pop();
    int v=p.second;
    if(dist1[v]<p.first){
      continue;
    }
    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));
      }
    }
  }

  for(int i=0;i<N;i++){
    printf("%lld\n",dist1[i]+min<ll>(dist1[i],dist1[i+N]));
  }

}
0