結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
TAISA_
|
| 提出日時 | 2019-07-05 22:04:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 788 ms / 2,000 ms |
| コード長 | 2,488 bytes |
| コンパイル時間 | 1,819 ms |
| コンパイル使用メモリ | 179,732 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-08 00:48:47 |
| 合計ジャッジ時間 | 4,880 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
};
template <typename T>
bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for(int i = 0; i < v.size(); i++) {
os << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
return os;
}
template <typename T>
vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
for(auto& e : t) {
fill_v(e, v);
}
};
ll n, m, p, q, t;
struct edge {
ll to, cost;
};
vector<vector<edge>> G;
vector<ll> dijkstra(int s) {
vector<ll> d(n, LINF);
priority_queue<P, vector<P>, greater<P>> q;
d[s] = 0;
q.push(P(0, s));
while(!q.empty()) {
int v = q.top().second;
q.pop();
for(auto e : G[v]) {
if(d[e.to] <= d[v] + e.cost)
continue;
d[e.to] = d[v] + e.cost;
q.push(P(d[e.to], e.to));
}
}
return d;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> p >> q >> t;
--p;
--q;
G.resize(n);
for(int i = 0; i < m; i++) {
ll a, b, c;
cin >> a >> b >> c;
--a;
--b;
G[a].push_back({b, c});
G[b].push_back({a, c});
}
auto d = dijkstra(0);
auto dp = dijkstra(p);
auto dq = dijkstra(q);
if(d[q] + dq[p] + dp[0] <= t) {
cout << t << endl;
return 0;
}
ll ans = -1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
ll t1 = d[i] + max(dq[i] + dq[j], dp[i] + dp[j]);
if(t1 + d[j] > t) {
continue;
}
chmax(ans, d[i] + t - t1);
}
}
cout << ans << endl;
}
TAISA_