結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
iomir
|
| 提出日時 | 2023-03-31 10:56:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 2,000 ms |
| コード長 | 1,318 bytes |
| コンパイル時間 | 1,923 ms |
| コンパイル使用メモリ | 177,372 KB |
| 実行使用メモリ | 10,720 KB |
| 最終ジャッジ日時 | 2024-09-22 16:10:39 |
| 合計ジャッジ時間 | 4,418 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
const ll INF=1ll<<60;
using vp=vector<pair<ll, ll>>;
using P = pair<ll,ll>;
using vvll = vector<vector<P>>;
ll N,M,p,Q,T;
vll dik(ll s,vvll &ab){
vll dist(N,INF);
priority_queue<P,vector<P>,greater<P>>q;
dist[s]=0;
q.push({0,s});
while(!q.empty()){
auto x=q.top();q.pop();
if(dist[x.second]<x.first)continue;
for(auto to:ab[x.second]){
if(dist[to.second]<=to.first+x.first)continue;
dist[to.second]=to.first+x.first;
q.push({dist[to.second],to.second});
}
}
return dist;
}
int main(){
cin>>N>>M>>p>>Q>>T;
p--;Q--;
vvll ab(N);
for(int i=0;i<M;i++){
ll a,b,c;
cin>>a>>b>>c;
a--;b--;
ab[a].push_back({c,b});
ab[b].push_back({c,a});
}
vll dist=dik(0,ab);
vll distp=dik(p,ab);
vll distq=dik(Q,ab);
ll ans=-1;
if(dist[p]+distp[Q]+dist[Q]<=T)ans=max(ans,T);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(max(distp[i]+distp[j],distq[i]+distq[j])+dist[i]+dist[j]<=T)ans=max(ans,T-(max(distp[i]+distp[j],distq[i]+distq[j])));
}
}
cout << ans << endl;
}
iomir