結果
問題 |
No.2805 Go to School
|
ユーザー |
![]() |
提出日時 | 2024-07-12 21:48:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 2,091 bytes |
コンパイル時間 | 3,045 ms |
コンパイル使用メモリ | 289,264 KB |
実行使用メモリ | 22,908 KB |
最終ジャッジ日時 | 2025-04-09 15:38:34 |
合計ジャッジ時間 | 6,934 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template <typename CostType> struct Edge { CostType cost; int src, dst; explicit Edge(const int src, const int dst, const CostType cost = 0) : cost(cost), src(src), dst(dst) {} auto operator<=>(const Edge& x) const = default; }; int main() { int n, m, l, s, e; cin >> n >> m >> l >> s >> e; vector<vector<Edge<int>>> graph(n); while (m--) { int a, b, t; cin >> a >> b >> t; --a; --b; graph[a].emplace_back(a, b, t); graph[b].emplace_back(b, a, t); } vector<int> has_wc(n, false); while (l--) { int t; cin >> t; --t; has_wc[t] = true; } vector<ll> dist(n * 2, LINF); dist[0] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que; que.emplace(dist[0], 0); while (!que.empty()) { const auto [d, i] = que.top(); que.pop(); if (d > dist[i]) continue; if (i < n && has_wc[i] && dist[i] <= s + e - 1 && chmin(dist[i + n], max(dist[i], ll{s}) + 1)) { que.emplace(dist[i + n], i + n); } for (const Edge<int>& edge : graph[i % n]) { const int dst = edge.dst + (i < n ? 0 : n); if (chmin(dist[dst], dist[i] + edge.cost)) que.emplace(dist[dst], dst); } } cout << (dist.back() == LINF ? -1 : dist.back()) << '\n'; return 0; }