結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
betit0919
|
| 提出日時 | 2019-07-07 19:43:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,096 bytes |
| コンパイル時間 | 1,143 ms |
| コンパイル使用メモリ | 111,448 KB |
| 実行使用メモリ | 6,972 KB |
| 最終ジャッジ日時 | 2024-10-07 01:09:28 |
| 合計ジャッジ時間 | 2,435 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 WA * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
template<class T = ll>
struct Edge {
int to;
T cost;
Edge() {}
Edge(int to, T cost) : to(to), cost(cost) {}
bool operator>(const Edge &r) const { return this->cost > r.cost; }
};
template<class T = ll>
vector<T> Dijkstra(vector<vector<Edge<T>>> &edges, int st) {
int V = (int)edges.size();
const int INF = numeric_limits<T>::max();
vector<T> dist(V, INF);
dist[st] = 0;
priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> p_que;
p_que.emplace(st, dist[st]);
while (!p_que.empty()) {
Edge<T> now(p_que.top().to, p_que.top().cost);
p_que.pop();
if (dist[now.to] < now.cost) continue;
for (const Edge<T> &e : edges[now.to]) {
T tmp_cost = now.cost + e.cost;
if (dist[e.to] > tmp_cost) {
dist[e.to] = tmp_cost;
p_que.emplace(e.to, dist[e.to]);
}
}
}
return dist;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll N,M,P,Q,T;
cin>>N>>M>>P>>Q>>T;
P--;Q--;
vector<vector<Edge<int> > > edges(N);
for(int i=0;i<M;i++){
int a,b,c;
cin>>a>>b>>c; a--; b--;
edges[a].emplace_back(b,c);
edges[b].emplace_back(a,c);
}
auto ans1 = Dijkstra<int>(edges,0);
auto ansq = Dijkstra<int>(edges,Q);
auto ansp = Dijkstra<int>(edges,P);
int p1=ans1[P],q1=ans1[Q],pq=ansq[P];
if(p1*2>T || q1*2>T){
cout<<-1<<endl;
}else if(p1+q1+pq<=T){
cout<<T<<endl;
}else{
int ans=INF;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if((ans1[i]+max(ansp[i]+ansp[j],ansq[i]+ansq[j])+ans1[j])<=T){
ans=min(ans,max(ansp[i]+ansp[j],ansq[i]+ansq[j]));
}
}
}
cout<<T-ans<<endl;
}
}
betit0919