結果

問題 No.807 umg tours
ユーザー mint6421mint6421
提出日時 2019-07-08 23:38:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 4,000 ms
コード長 2,264 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 180,268 KB
実行使用メモリ 56,064 KB
最終ジャッジ日時 2024-05-02 23:55:23
合計ジャッジ時間 8,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 239 ms
44,296 KB
testcase_12 AC 263 ms
31,292 KB
testcase_13 AC 371 ms
44,344 KB
testcase_14 AC 147 ms
20,700 KB
testcase_15 AC 115 ms
17,456 KB
testcase_16 AC 386 ms
48,432 KB
testcase_17 AC 486 ms
53,964 KB
testcase_18 AC 473 ms
53,908 KB
testcase_19 AC 466 ms
53,892 KB
testcase_20 AC 275 ms
28,504 KB
testcase_21 AC 324 ms
29,556 KB
testcase_22 AC 124 ms
14,480 KB
testcase_23 AC 95 ms
12,032 KB
testcase_24 AC 262 ms
40,908 KB
testcase_25 AC 481 ms
56,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:82:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   82 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;




template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  WG<int> es(2*n);

  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    es[a*2+1].PB(edge<int>(b*2+1,c));
    es[a*2+1].PB(edge<int>(b*2,0));
    es[a*2].PB(edge<int>(b*2,c));
    es[b*2+1].PB(edge<int>(a*2+1,c));
    es[b*2+1].PB(edge<int>(a*2,0));
    es[b*2].PB(edge<int>(a*2,c));
  }

  vector<int> res1=dijkstra(es,1);
  vector<int> res2=dijkstra(es,0);

  rep(i,n){
    cout<<min(res1[i*2+1],res1[i*2])+res2[i*2]<<endl;
  }

}


0