結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-07-12 21:17:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 447 ms / 2,000 ms |
コード長 | 1,216 bytes |
コンパイル時間 | 4,727 ms |
コンパイル使用メモリ | 260,212 KB |
最終ジャッジ日時 | 2025-02-22 03:27:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <stdio.h>#include <bits/stdc++.h>#include <atcoder/all>using namespace atcoder;using mint = modint998244353;using namespace std;#define rep(i,n) for (int i = 0; i < (n); ++i)#define Inf32 1000000001#define Inf64 1000000000000000001vector<long long> get(vector<vector<pair<int,long long>>> &G, int s){int N = G.size();vector<long long> d(N,Inf64);d[s] = 0;priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> pq;pq.push({0,s});while(!pq.empty()){auto [c,v] = pq.top();pq.pop();if(d[v] < c) continue;for(auto [u,w] : G[v]){if(d[u] > d[v] + w){d[u] = d[v] + w;pq.push({d[u],u});}}}return d;}int main(){int N,M,L,S,E;cin>>N>>M>>L>>S>>E;vector<vector<pair<int,long long>>> G(N);rep(i,M){int a,b;long long c;cin>>a>>b>>c;a--,b--;G[a].push_back({b,c});G[b].push_back({a,c});}auto dx = get(G,0), dy = get(G,N-1);long long ans = Inf64;E += S;rep(i,L){long long t;cin>>t;t--;long long d0 = dx[t];if(d0 >= E)continue;if(dy[t]==Inf64)continue;d0 = max(d0,(long long)S);ans = min(ans,d0+1+dy[t]);}if(ans==Inf64)ans = -1;cout<<ans<<endl;return 0;}