結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-03-30 00:35:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,078 bytes |
| コンパイル時間 | 1,563 ms |
| コンパイル使用メモリ | 166,396 KB |
| 実行使用メモリ | 24,356 KB |
| 最終ジャッジ日時 | 2025-01-02 16:07:58 |
| 合計ジャッジ時間 | 4,075 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 WA * 19 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
int dxy[] = {0, 1, 0, -1, 0};
void solve();
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
#if DEBUG
#define SIZE 5
#else
#define SIZE 2222
#endif
int N,M,P,Q,T;
typedef pair<int, int> Edge;
typedef pair<int, int> I;
vector< vector<Edge> > E;
int DP[3][SIZE];
void dijkstra(int a, int s) {
auto dp = DP[a];
REP(i,SIZE) dp[i]=LONG_LONG_MAX;
priority_queue<I, vector<I>, greater<I>> que;
dp[s]=0;
que.push(*new I(0,s));
while(que.size()) {
I i = que.top();
que.pop();
if (i.first > dp[i.second]) continue;
for (auto e:E[i.second]) {
int c = i.first + e.second;
if (dp[e.first] > c) {
dp[e.first] = c;
que.push(*new I(c, e.first));
}
}
}
}
void solve() {
cin>>N>>M>>P>>Q>>T;
P--, Q--;
int a,b,c;
E.resize(N);
REP(i,M) {
cin>>a>>b>>c;
a--,b--;
E[a].push_back(*new Edge(b,c));
E[b].push_back(*new Edge(a,c));
}
dijkstra(0, 0);
dijkstra(1, P);
dijkstra(2, Q);
if ((DP[0][P] + DP[1][Q] + DP[2][0]) <= T) {
cout << T << endl;
return;
}
int ans = -1;
REP(i,N) {
int d = max(DP[2][i], DP[1][i]) * 2;
int t = 2*DP[0][i] + d;
if (t > T) continue;
ans = max(ans, T-d);
}
cout << ans << endl;
}
koyopro