結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-07-12 21:56:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 2,214 bytes |
コンパイル時間 | 3,203 ms |
コンパイル使用メモリ | 264,012 KB |
実行使用メモリ | 27,800 KB |
最終ジャッジ日時 | 2024-07-16 01:39:22 |
合計ジャッジ時間 | 8,297 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, l, st, ed; cin >> n >> m >> l >> st >> ed; struct Edge { int from; int to; int cost; Edge(int from, int to, int cost) :from(from), to(to), cost(cost) {} }; ed += st; vector to(n, vector<Edge>()); vector<bool>t(n); rep(i, m) { int a, b, t; cin >> a >> b >> t; a--, b--; to[a].push_back(Edge(a, b, t)); to[b].push_back(Edge(b, a, t)); } rep(i, l) { int p; cin >> p; p--; t[p] = true; } vector dp(n, vector<long long>(2, LINF)); dp[0][0] = 0; std::priority_queue<std::pair<long long, P>, std::vector<std::pair<long long, P>>, std::greater<std::pair<long long, P>>> pq; pq.push({ 0,{0,0} }); while (!pq.empty()) { auto top = pq.top(); long long cost = top.first; int pos = top.second.first; int flg = top.second.second; pq.pop(); if (dp[pos][flg] < cost) continue; for (auto e : to[pos]) { { long long ncost = cost + e.cost; long long npos = e.to; if (chmin(dp[npos][flg], ncost)) { pq.push({ ncost,{npos,flg} }); } } if (0 == flg && t[pos]) { long long ncost = cost; if (ncost >= ed)continue; chmax(ncost, st); ncost += 1; long long npos = pos; if (chmin(dp[npos][1], ncost)) { pq.push({ ncost,{npos,1} }); } } } } if (dp[n - 1][1] == LINF)dp[n - 1][1] = -1; cout << dp[n - 1][1] << endl; return 0; }