結果
問題 |
No.2805 Go to School
|
ユーザー |
|
提出日時 | 2024-07-13 19:48:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 315 ms / 2,000 ms |
コード長 | 1,737 bytes |
コンパイル時間 | 2,014 ms |
コンパイル使用メモリ | 214,488 KB |
実行使用メモリ | 28,032 KB |
最終ジャッジ日時 | 2025-04-09 15:41:54 |
合計ジャッジ時間 | 8,151 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll INF = 1e18; void solve() { ll n, m, L, S, E; cin >> n >> m >> L >> S >> E; vector<vector<pair<ll, ll>>> g(n); { map<pair<ll, ll>, ll> mp; rep(mi, m) { ll a, b, t; cin >> a >> b >> t, a--, b--; pair<ll, ll> k = {a, b}; if (mp.count(k) == 1) t = min(t, mp[k]); mp[k] = t; } for (const auto &[k, t] : mp) { const auto [a, b] = k; g[a].emplace_back(b, t); g[b].emplace_back(a, t); } } vector<bool> f(n, false); rep(i, L) { ll t; cin >> t, t--; f[t] = true; } priority_queue<pair<ll, ll>> que; vector<ll> dist(n, INF); que.emplace(0, 0); dist[0] = 0; rep(ti, 2) { while (!que.empty()) { auto [cd, u] = que.top(); que.pop(); cd *= -1; if (dist[u] < cd) continue; for (const auto &[v, t] : g[u]) { ll nd = cd + t; if (dist[v] <= nd) continue; dist[v] = nd; que.emplace(-dist[v], v); } } if (ti) break; priority_queue<pair<ll, ll>> nex; rep(i, n) { if (!f[i]) { dist[i] = INF; } else if (dist[i] <= S) { dist[i] = S + 1; } else if (dist[i] < S + E) { dist[i] += 1; } else { dist[i] = INF; } if (dist[i] < INF) { nex.emplace(-dist[i], i); } } swap(que, nex); } ll ans = dist[n - 1]; if (ans == INF) ans = -1; cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }