結果
問題 |
No.848 なかよし旅行
|
ユーザー |
![]() |
提出日時 | 2019-07-23 19:23:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,439 bytes |
コンパイル時間 | 1,463 ms |
コンパイル使用メモリ | 175,532 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-10-07 02:18:35 |
合計ジャッジ時間 | 3,768 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 19 |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll>P; ll N, M, T; ll st[3] = {1, 0, 0}; vector<P>path[2020]; ll cost[3][2020]; int main(){ cin >> N >> M >> st[1] >> st[2] >> T; for(ll i = 0; i < M; i++){ ll a, b, c; cin >> a >> b >> c; path[a].push_back(P(b, c)); path[b].push_back(P(a, c)); } for(ll i = 0; i < 3; i++){ for(ll j = 0; j < 2020; j++)cost[i][j] = -1; priority_queue<P, vector<P>, greater<P> >Q; Q.push(P(0, st[i])); while(!Q.empty()){ ll idx = Q.top().second; ll cst = Q.top().first; Q.pop(); if(cost[i][idx] >= 0)continue; cost[i][idx] = cst; for(ll j = 0; j < path[idx].size(); j++){ ll nxt = path[idx][j].first; ll w = path[idx][j].second; if(cost[i][nxt] < 0){ Q.push(P(cst + w, nxt)); } } } } ll ans = -1; for(ll i = 1; i <= N; i++){ // cout << cost[0][i] << ", " << cost[1][i] << ", " << cost[2][i] << endl; if(T >= 2 * (cost[0][i] + cost[1][i] + cost[2][i])){ ans = T; } else if(T >= 2 * cost[0][i] + 2 * max(cost[1][i], cost[2][i])){ ans = max(ans, T - 2 * max(cost[1][i], cost[2][i])); } } cout << ans << endl; return 0; }