結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-05 22:34:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,570 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 183,204 KB |
| 実行使用メモリ | 54,296 KB |
| 最終ジャッジ日時 | 2024-10-06 22:33:41 |
| 合計ジャッジ時間 | 8,292 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
ll INF = 1010101010101010LL;
vector<vector<pair<int, ll>>> ps;
struct N {
ll i, d;
N(int i, ll d) : i(i), d(d) {}
};
bool operator<(const N &l, const N &r) {
return l.d > r.d;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n, m, p, q, t;
cin >> n >> m >> p >> q >> t;
p--;
q--;
vector<vector<ll>> cost(n, vector<ll>(n, INF));
ps.resize(n);
for (int i = 0; i < m; i++) {
ll a, b, c;
cin >> a >> b >> c;
a--;
b--;
ps[a].emplace_back(b, c);
ps[b].emplace_back(a, c);
}
priority_queue<N> queue;
for (int i = 0; i < n; i++) {
queue.emplace(i, 0);
while (queue.size()) {
auto v = queue.top();
queue.pop();
if (cost[i][v.i] < INF) continue;
cost[i][v.i] = v.d;
for (auto &path : ps[v.i]) {
if (cost[i][path.first] < INF) continue;
queue.emplace(path.first, v.d + path.second);
}
}
}
ll ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ll pcost = cost[i][p] + cost[p][j];
ll qcost = cost[i][q] + cost[q][j];
ll ijcost = cost[0][i] + cost[j][0];
if (max(pcost, qcost) + ijcost <= t) {
ans = max(ans, t - max(pcost, qcost));
}
if (ijcost + pcost + qcost <= t) ans = t;
}
}
if (cost[0][p] + cost[p][q] + cost[q][0] <= t) ans = t;
cout << ans << endl;
return 0;
}