結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2024-01-23 06:20:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,393 bytes |
| コンパイル時間 | 2,270 ms |
| コンパイル使用メモリ | 204,656 KB |
| 最終ジャッジ日時 | 2025-02-18 22:13:18 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 WA * 19 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
const ll INF=1LL<<60;
struct Edge{
int to;
ll w;
Edge(int to,ll w) : to(to),w(w) {}
};
using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;
template<class T> bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
Graph G;
vector<ll> dijkstra(int s){
int n=G.size();
vector<ll> dist(n,INF);
dist[s]=0;
priority_queue<pli,vector<pli>,greater<pli>> que;
que.push({dist[s],s});
while(!que.empty()){
int v=que.top().second;
ll d=que.top().first;
que.pop();
if(d>dist[v]) continue;
for(auto e:G[v]){
if(chmin(dist[e.to],dist[v]+e.w)){
que.push({dist[e.to],e.to});
}
}
}
return dist;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,m,p,q,t;
cin>>n>>m>>p>>q>>t;
p--,q--;
G.resize(n);
rep(i,m){
int a,b;
ll c;
cin>>a>>b>>c;
a--,b--;
G[a].push_back(Edge(b,c));
G[b].push_back(Edge(a,c));
}
vector<ll> dp=dijkstra(p);
vector<ll> dq=dijkstra(q);
vector<ll> d0=dijkstra(0);
ll ans=-1;
rep(i,n){
ll tmp=t-max(2*dp[i],2*dq[i]);
if(tmp>=2*d0[i]) ans=max(ans,tmp);
}
if(dp[0]+dq[0]+dp[q]<=t) cout<<t<<endl;
else cout<<ans<<endl;
return 0;
}
umezo