結果

問題 No.848 なかよし旅行
ユーザー どららどらら
提出日時 2019-07-07 15:39:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,535 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 173,636 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2024-04-16 09:02:22
合計ジャッジ時間 6,382 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
10,880 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 AC 90 ms
8,172 KB
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 12 ms
5,376 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 RE -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll N, M, P, Q, T;
vector<pair<ll,ll>> G[2005];

void dijkstra(vector<ll>& dist, ll st){
  vector<bool> visited(N, false);
  dist[st] = 0;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
  q.push(make_pair(0,st));
  while(!q.empty()){
    pair<ll,ll> p = q.top();
    q.pop();

    if(visited[p.second]) continue;
    visited[p.second] = true;
    dist[p.second] = p.first;
    FOR(it,G[p.second]){
      if(!visited[it->first]){
        q.push(make_pair(p.first + it->second, it->first));
      }
    }
  }
}


int main(){
  cin >> N >> M >> P >> Q >> T;
  rep(i,M){
    ll a, b, c;
    cin >> a >> b >> c;
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }

  vector<ll> dist_st(N,-1), dist_P(N,-1), dist_Q(N,-1);
  dijkstra(dist_st, 1);
  dijkstra(dist_P, P);
  dijkstra(dist_Q, Q);

  ll ret = -1;
  if(dist_st[P] + dist_P[Q] + dist_st[Q] <= T){
    ret = T;
  }
  
  REP(x,1,N+1){
    REP(y,1,N+1){
      ll sum = dist_st[x];
      sum += max(dist_P[x], dist_Q[x]);
      sum += max(dist_P[y], dist_Q[y]);
      sum += dist_st[y];
      if(sum <= T){
        ret = max(ret, T - max(dist_P[x], dist_Q[x]) - max(dist_P[y], dist_Q[y]));
      }
    }
  }

  cout << ret << endl;
  
  return 0;
}
0