結果
問題 | No.2805 Go to School |
ユーザー | Today03 |
提出日時 | 2024-07-12 21:45:46 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 302 ms / 2,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 2,070 ms |
コンパイル使用メモリ | 215,052 KB |
実行使用メモリ | 22,124 KB |
最終ジャッジ日時 | 2024-07-16 01:38:59 |
合計ジャッジ時間 | 8,430 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { int N, M, L; ll S, E; cin >> N >> M >> L >> S >> E; vector<vector<pair<int, ll>>> G(N); for (int i = 0; i < M; i++) { int a, b; ll t; cin >> a >> b >> t; a--; b--; G[a].push_back({b, t}); G[b].push_back({a, t}); } vector<bool> T(N, false); for (int i = 0; i < L; i++) { int t; cin >> t; t--; T[t] = true; } priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq; pq.push({0, 0}); vector<ll> D(2 * N, INFL); D[0] = 0; while (!pq.empty()) { auto [nowd, now] = pq.top(); pq.pop(); bool done = now >= N; int nowv = now % N; if (D[now] < nowd) { continue; } for (auto [to, cost] : G[nowv]) { int nxt = to; if (done) { nxt += N; } if (D[nxt] > D[now] + cost) { D[nxt] = D[now] + cost; pq.push({D[nxt], nxt}); } } if (T[nowv] && !done && nowd < S + E) { int nxt = now + N; ll nxtt = max(S + 1, nowd + 1); if (D[nxt] > nxtt) { D[nxt] = nxtt; pq.push({D[nxt], nxt}); } } } ll ans = D[N * 2 - 1]; if (ans == INFL) { ans = -1; } cout << ans << endl; }