結果
問題 |
No.2805 Go to School
|
ユーザー |
|
提出日時 | 2024-07-30 22:03:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,693 bytes |
コンパイル時間 | 2,183 ms |
コンパイル使用メモリ | 178,804 KB |
実行使用メモリ | 16,052 KB |
最終ジャッジ日時 | 2024-07-30 22:03:26 |
合計ジャッジ時間 | 9,227 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 TLE * 1 -- * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define INF 1e9 struct Edge { int to; int dist; Edge(int to, int dist) : to(to), dist(dist) {} bool operator=(const Edge &rhs) const { return to == rhs.to; } }; vector<int> dijkstra(int N, int s, vector<vector<Edge>> &graph) { vector<int> distance(N, INF); vector<int> from(N, -1); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; distance[s] = 0; q.push({0, s}); while (!q.empty()) { pair<int, int> p = q.top(); q.pop(); int path_now = p.first; int p_now = p.second; if (distance[p_now] < path_now) continue; for (Edge e : graph[p_now]) { int path_new = path_now + e.dist; int p_new = e.to; if (path_new < distance[p_new]) { distance[p_new] = path_new; from[p_new] = p_now; q.push({path_new, p_new}); } } } return distance; } int main() { int n, m, l, s, e; cin >> n >> m >> l >> s >> e; vector<vector<Edge>> g(n); rep(i, m) { int a, b, t; cin >> a >> b >> t; a--; b--; g[a].push_back(Edge(b, t)); g[b].push_back(Edge(a, t)); } vector<int> t(n, 0); rep(i, l) { int ti; cin >> ti; ti--; t[ti] = 1; } vector<int> d = dijkstra(n, 0, g); int ans = INF; rep(i, n) { if (t[i] == 1 && d[i] >= s && d[i] <= s + e) { ans = min(d[n-1] + 1, ans); } } if (ans == INF) { rep(i, n) { if (t[i] == 1 && d[i] < s) { vector<int> u = dijkstra(n, i, g); ans = min(s + 1 + u[n-1], ans); } } } if (ans == INF) cout << -1 << endl; else cout << ans << endl; return 0; }