結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
cotton_fn_
|
| 提出日時 | 2019-07-05 22:04:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,115 bytes |
| コンパイル時間 | 1,370 ms |
| コンパイル使用メモリ | 121,796 KB |
| 最終ジャッジ日時 | 2025-01-07 05:58:45 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 WA * 19 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs
template<class T>
vector<i64> djk(const T& e, i64 n, i64 s) {
vector<i64> d(n + 1, 1e18);
vector<bool> fix(n + 1);
using P = pair<i64, i64>;
priority_queue<P, vector<P>, greater<P>> pq;
d[s] = 0;
pq.emplace(0, s);
while (!pq.empty()) {
P p = pq.top(); pq.pop();
i64 u = p.second;
if (fix[u]) continue;
fix[u] = true;
for (const P& q : e[u]) {
i64 cv = q.first, v = q.second;
if (!fix[v] && d[u] + cv < d[v]) {
pq.emplace(d[u] + cv, v);
d[v] = d[u] + cv;
}
}
}
return d;
}
i64 n, m, p, q, t;
vector<vector<pair<i64, i64>>> g;
int main() {
cin >> n >> m >> p >> q >> t;
init_n(g, n + 1);
for (i64 i = 0; i < m; ++i) {
i64 a, b, c;
cin >> a >> b >> c;
g[a].emplace_back(c, b);
g[b].emplace_back(c, a);
}
auto d1 = djk(g, n, 1);
auto dp = djk(g, n, p);
auto dq = djk(g, n, q);
bool ok = false;
i64 ans = 0;
if (d1[p] + dp[q] + dq[1] <= t
|| 2 * (d1[p] + d1[q]) <= t) {
ans = t;
ok = true;
}
for (i64 u = 1; u < n; ++u) {
i64 x = 2 * max(dp[u], dq[u]);
if (2 * d1[u] + x <= t) {
ans = max(ans, t - x);
ok = true;
}
}
if (!ok) ans = -1;
cout << ans << endl;
return 0;
}
cotton_fn_