結果

問題 No.848 なかよし旅行
ユーザー snow39snow39
提出日時 2019-07-06 00:34:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 103,848 KB
実行使用メモリ 10,860 KB
最終ジャッジ日時 2024-04-16 08:17:43
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,M,P,Q,T;

vector<pair<int,ll>> g[2020];

ll dist[3][2020];

const ll INF=1e18;

void dijkstra(int id,int start){
  for(int i=1;i<=N;i++) dist[id][i]=INF;

  dist[id][start]=0;
  priority_queue<pair<ll,int>> PQ;
  PQ.push(mkp(0,start));
  while(!PQ.empty()){
    int co,tp;
    tie(co,tp)=PQ.top();
    PQ.pop();

    co*=(-1);
    if(dist[id][tp]<co) continue;

    for(int i=0;i<g[tp].size();i++){
      int nex=g[tp][i].first;
      ll neco=g[tp][i].second;
      if(co+neco<dist[id][nex]){
        dist[id][nex]=co+neco;
        PQ.push(mkp(-dist[id][nex],nex));
      }
    }
  }
}

int main(){
  cin>>N>>M>>P>>Q>>T;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    g[a].push_back(mkp(b,c));
    g[b].push_back(mkp(a,c));
  }

  dijkstra(0,1);
  dijkstra(1,P);
  dijkstra(2,Q);

  if(dist[0][P]+dist[1][Q]+dist[2][1]<=T){
    cout<<T<<endl;
    return 0;
  }

  ll ans=-1;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      ll p=dist[1][i]+dist[1][j];
      ll q=dist[2][i]+dist[2][j];
      ll r=dist[0][i]+dist[0][j];

      if(i==3&&j==3){
        cout<<p<<" "<<q<<" "<<r<<endl;
      }

      if(max(p,q)+r<=T){
        ans=max(ans,T-max(p,q));
      }
    }
  }

  cout<<ans<<endl;



  return 0;
}
0