結果
問題 |
No.848 なかよし旅行
|
ユーザー |
![]() |
提出日時 | 2019-07-05 22:15:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,997 bytes |
コンパイル時間 | 2,042 ms |
コンパイル使用メモリ | 103,576 KB |
実行使用メモリ | 13,188 KB |
最終ジャッジ日時 | 2024-10-06 22:01:54 |
合計ジャッジ時間 | 2,867 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 19 |
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cassert> #include <cstdint> #include <iostream> #include <iomanip> #include <string> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #include <algorithm> #include <numeric> #include <bitset> using namespace std; using ll = long long; using Pll = pair<ll, ll>; using Pii = pair<int, int>; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; constexpr int MAX_N = 2000; vector< vector<Pll> > edges(MAX_N); class Dijkstra { public: ll d[MAX_N]; priority_queue< Pll, vector<Pll>, greater<Pll> > que; ll start = -1; Dijkstra(ll start): start(start) { fill(d, d+MAX_N, 1LL<<60); d[start] = 0; que.push(Pll(0, start)); while(!que.empty()){ Pll v = que.top(); que.pop(); if(d[v.second] < v.first) continue; for(Pll e: edges[v.second]){ if(d[e.first] > d[v.second] + e.second){ d[e.first] = d[v.second] + e.second; que.push(Pll(d[e.first], e.first)); } } } } ll get(ll x) { return d[x]; } }; int main() { int n,m,p,q; ll t; cin >> n >> m >> p >> q >> t; --p; --q; int a,b; ll c; for(int i=0;i<m;++i){ cin >> a >> b >> c; --a; --b; edges[a].emplace_back(b, c); edges[b].emplace_back(a, c); } Dijkstra d_0 = Dijkstra(0), d_p = Dijkstra(p), d_q = Dijkstra(q); ll ans = -1LL; if(d_0.get(p) + d_p.get(q) + d_q.get(0) <= t) { ans = t; } else { for(int r=0;r<n;++r) { ll tt = 2 * (d_0.get(r) + max(d_p.get(r), d_q.get(r))); // cerr << r+1 << ": " << tt << endl; if(tt > t) continue; ans = max(t-tt+2*d_0.get(r), ans); } } cout << ans << endl; }