結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-09 14:06:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,744 bytes |
| コンパイル時間 | 2,041 ms |
| コンパイル使用メモリ | 181,840 KB |
| 実行使用メモリ | 15,652 KB |
| 最終ジャッジ日時 | 2024-09-13 07:08:41 |
| 合計ジャッジ時間 | 6,116 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 WA * 19 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using Pll = pair<ll,ll>;
const ll INF = 1e18;
const int MOD = 1000000007;
ll v = 2005,e;
vector<vector<pair<ll,ll>>> graph(v,vector<pair<ll,ll>>());
vector<ll> dijkstra(ll start){
vector<ll> shortest(v);
vector<bool> visited(v,false);
priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
pq.push(make_pair(0,start));
while (!pq.empty()){
pair<ll,ll> now = pq.top();
pq.pop();
ll cost,node;
tie(cost,node) = now;
if(visited[node]){
continue;
}else{
shortest[node] = cost;
visited[node] = true;
for(pair<ll,ll> next:graph[node]){
ll next_cost,next_node;
tie(next_cost,next_node) = next;
pq.push(make_pair(cost+next_cost,next_node));
}
}
}
return shortest;
}
int main(){
int p,q;
ll time;
cin >> v >> e >> p >> q >> time;
--p;--q;
rep(i,e){
int a,b;
ll c;
cin >> a >> b >> c;
--a;--b;
graph[a].push_back(Pll(c,b));
graph[b].push_back(Pll(c,a));
}
vector<ll> dis_zero = dijkstra(0);
vector<ll> dis_p = dijkstra(p);
vector<ll> dis_q = dijkstra(q);
if(dis_zero[p] + dis_p[q] + dis_zero[q] <= time){
cout << time << endl;
return 0;
}
ll ans = -1;
rep(i,v){
ll s = dis_zero[i];
ll t = dis_p[i];
ll u = dis_q[i];
if(2*(s+t) <= time && 2*(s+u) <= time){
ans = max(ans,time - 2*max(t,u));
}
}
cout << ans << endl;
return 0;
}