結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2024-07-19 16:51:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 2,040 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 105,456 KB |
最終ジャッジ日時 | 2025-02-23 16:15:43 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <iostream>#include <queue>#include <vector>#include <climits>#include <functional>using namespace std;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int N, M, L, S, E, i, a, b, t;long long ans = LONG_LONG_MAX;cin >> N >> M >> L >> S >> E;vector<vector<pair<int, int>>> edges(N, vector<pair<int, int>>());vector<int> T(L);vector<long long> dist_from_start(N, LONG_LONG_MAX), dist_from_goal(N, LONG_LONG_MAX);for (i = 0; i != M; ++i){cin >> a >> b >> t, --a, --b;edges[a].emplace_back(t, b);edges[b].emplace_back(t, a);}for (i = 0; i != L; ++i)cin >> T[i], --T[i];priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;pq.emplace(dist_from_start[0] = 0, 0);while (!pq.empty()){if (pq.top().first == dist_from_start[pq.top().second]){for (i = 0; i != edges[pq.top().second].size(); ++i)if (dist_from_start[edges[pq.top().second][i].second] > pq.top().first + edges[pq.top().second][i].first)pq.emplace(dist_from_start[edges[pq.top().second][i].second] = pq.top().first + edges[pq.top().second][i].first, edges[pq.top().second][i].second);}pq.pop();}pq.emplace(dist_from_goal[N - 1] = 0, N - 1);while (!pq.empty()){if (pq.top().first == dist_from_goal[pq.top().second]){for (i = 0; i != edges[pq.top().second].size(); ++i)if (dist_from_goal[edges[pq.top().second][i].second] > pq.top().first + edges[pq.top().second][i].first)pq.emplace(dist_from_goal[edges[pq.top().second][i].second] = pq.top().first + edges[pq.top().second][i].first, edges[pq.top().second][i].second);}pq.pop();}for (i = 0; i != L; ++i)if (dist_from_start[T[i]] < S + E && dist_from_goal[T[i]] != LONG_LONG_MAX && max(static_cast<long long>(S), dist_from_start[T[i]]) + 1 +dist_from_goal[T[i]] < ans)ans = max(static_cast<long long>(S), dist_from_start[T[i]]) + 1 + dist_from_goal[T[i]];if (ans == LONG_LONG_MAX)cout << "-1\n";elsecout << ans << '\n';return 0;}