結果

問題 No.848 なかよし旅行
ユーザー beetbeet
提出日時 2019-07-05 21:44:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 207,700 KB
実行使用メモリ 10,564 KB
最終ジャッジ日時 2023-08-07 19:39:11
合計ジャッジ時間 4,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
10,564 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 35 ms
5,508 KB
testcase_12 AC 45 ms
5,692 KB
testcase_13 AC 60 ms
6,660 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 57 ms
6,400 KB
testcase_16 AC 95 ms
8,060 KB
testcase_17 AC 69 ms
7,168 KB
testcase_18 AC 33 ms
5,272 KB
testcase_19 AC 30 ms
4,608 KB
testcase_20 AC 15 ms
4,384 KB
testcase_21 AC 81 ms
7,344 KB
testcase_22 AC 85 ms
7,220 KB
testcase_23 AC 14 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 102 ms
8,104 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 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;
}

//INSERT ABOVE HERE
signed main(){
  Int n,m,p,q,t;
  cin>>n>>m>>p>>q>>t;
  p--;q--;
  using P = pair<Int, Int>;
  vector< vector<P> > G(n);
  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);
  }
  auto d0=dijkstra(0,G);
  auto dp=dijkstra(p,G);
  auto dq=dijkstra(q,G);

  if(d0[p]+dp[q]+dq[0]<=t){
    cout<<t<<endl;
    return 0;
  }

  Int ans=-1;
  for(Int x=0;x<n;x++){
    for(Int y=0;y<n;y++){
      Int res=0;
      chmax(res,dp[x]+dp[y]);
      chmax(res,dq[x]+dq[y]);
      if(d0[x]+res+d0[y]<=t) chmax(ans,t-res);
    }
  }
  cout<<ans<<endl;
  return 0;
}
0