結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-06-14 19:43:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,922 bytes |
| コンパイル時間 | 1,543 ms |
| コンパイル使用メモリ | 173,928 KB |
| 実行使用メモリ | 18,200 KB |
| 最終ジャッジ日時 | 2024-06-27 19:49:16 |
| 合計ジャッジ時間 | 4,654 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 WA * 19 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.06.14 19:43:30
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T>
struct Dijkstra {
private:
int V;
struct edge { int to; T cost; };
vector<vector<edge>> G;
public:
const T inf = numeric_limits<T>::max();
vector<T> d;
Dijkstra(int V) : V(V) {
G.resize(V);
}
void add_edge(int from, int to, T weight, bool directed = false) {
G[from].push_back({to,weight});
if (!directed) G[to].push_back({from,weight});
}
void build(int s) {
d.assign(V, inf);
typedef tuple<T, int> P;
priority_queue<P, vector<P>, greater<P>> pq;
d[s] = 0;
pq.push(P(d[s], s));
while (!pq.empty()) {
P p = pq.top(); pq.pop();
int v = get<1>(p);
if (d[v] < get<0>(p)) continue;
for (const edge &e : G[v])
{
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
pq.push(P(d[e.to], e.to));
}
}
}
}
};
int main() {
int n,m,p,q,t;cin >> n >> m >> p >> q >> t;
p--;q--;
Dijkstra<ll> g1(n),gp(n),gq(n);
for (int i = 0; i < m; i++) {
int u,v,c;cin >> u >> v >> c;
u--;v--;
g1.add_edge(u,v,c);
gp.add_edge(u,v,c);
gq.add_edge(u,v,c);
}
g1.build(0);
gp.build(p);
gq.build(q);
if (g1.d[p] + gp.d[q] + gq.d[0] <= t) {
cout << t << endl;
return 0;
}
ll ans = -1;
for (int i = 0; i < n; i++) {
ll t1 = g1.d[i];
ll tp = gp.d[i];
ll tq = gq.d[i];
ll aaa = max(tp,tq);
if (2 * t1 + 2 * aaa > t) continue;
ans = max(ans,t - 2 * aaa);
}
cout << ans << endl;
return 0;
}
🍮かんプリン