結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
sprng_wl
|
| 提出日時 | 2019-07-06 02:38:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 152 ms / 2,000 ms |
| コード長 | 1,249 bytes |
| コンパイル時間 | 1,719 ms |
| コンパイル使用メモリ | 170,088 KB |
| 実行使用メモリ | 10,660 KB |
| 最終ジャッジ日時 | 2024-11-08 00:56:42 |
| 合計ジャッジ時間 | 3,640 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define Int int64_t
using namespace std;
using P = pair<Int, Int>;
struct edge { int to; Int cost; };
void dijkstra(vector<vector<edge>>& G, vector<Int>& d, int s) {
priority_queue<P, vector<P>, greater<P>> que;
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first) { continue; }
for (int i = 0; i < G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
const Int INF = 1e18;
Int N, M, P, Q, T;
cin >> N >> M >> P >> Q >> T;
--P; --Q;
vector<vector<edge>> G(N);
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b >> c;
--a; --b;
G[a].push_back({b, c});
G[b].push_back({a, c});
}
vector<Int> d0(N, INF), dP(N, INF), dQ(N, INF);
dijkstra(G, d0, 0);
dijkstra(G, dP, P);
dijkstra(G, dQ, Q);
if (d0[P] + dP[Q] + dQ[0] <= T) {
cout << T << endl;
return 0;
}
Int res = -1;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
Int x = d0[i] + d0[j];
Int y = max(dP[i] + dP[j], dQ[i] + dQ[j]);
if (x + y <= T) {
res = max(res, T - y);
}
}
}
cout << res << endl;
return 0;
}
sprng_wl