結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-07-12 22:13:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 1,176 bytes |
コンパイル時間 | 2,372 ms |
コンパイル使用メモリ | 209,488 KB |
最終ジャッジ日時 | 2025-02-22 04:13:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;const ll LNF = LLONG_MAX;vector<ll> dijkstra(vector<vector<pair<int, int>>>& to, int s) {using P = tuple<ll, int>;priority_queue<P, vector<P>, greater<P>> pq;int n = to.size();vector<ll> dp(n, LNF);dp[s] = 0;pq.emplace(0, s);while (pq.size()) {auto [c, v] = pq.top(); pq.pop();if (dp[v] != c) continue;for (auto [u, w] : to[v]) {if (dp[u] <= c + w) continue;dp[u] = c + w;pq.emplace(c + w, u);}}return dp;}int main() {ll n, m, l, s, e; cin >> n >> m >> l >> s >> e;vector to(n, vector<pair<int, int>>());for (int i = 0; i < m; i++) {int u, v, w; cin >> u >> v >> w;u--, v--;to[u].emplace_back(v, w);to[v].emplace_back(u, w);}vector<int> T(l);for (int i = 0; i < l; i++) cin >> T[i], T[i]--;auto dp_0 = dijkstra(to, 0);auto dp_n = dijkstra(to, n - 1);ll ans = LNF;for (auto t : T) {if (dp_0[t] == LNF or dp_n[t] == LNF) continue;if (dp_0[t] <= s + e - 1) {ans = min(max(dp_0[t] + 1, s + 1) + dp_n[t], ans);}}if (ans == LNF) ans = -1;cout << ans << endl;}