結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2024-07-12 21:13:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 207 ms / 2,000 ms |
| コード長 | 1,510 bytes |
| コンパイル時間 | 2,327 ms |
| コンパイル使用メモリ | 206,520 KB |
| 実行使用メモリ | 28,136 KB |
| 最終ジャッジ日時 | 2025-04-09 15:36:10 |
| 合計ジャッジ時間 | 6,820 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=15LL<<58;
vector<pair<int,ll>> G[MAX];
ll dis[MAX][2];
bool OK[MAX];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
ll N,M,L,S,E;cin>>N>>M>>L>>S>>E;
for(int i=0;i<M;i++){
int a,b,c;cin>>a>>b>>c;
a--;b--;
G[a].push_back(mp(b,c));
G[b].push_back(mp(a,c));
}
for(int i=0;i<L;i++){
int x;cin>>x;x--;
OK[x]=true;
}
for(int i=0;i<N;i++) dis[i][0]=dis[i][1]=INF;
priority_queue<tuple<ll,int,int>,vector<tuple<ll,int,int>>,greater<tuple<ll,int,int>>> PQ;
dis[0][0]=0;
PQ.push({0,0,0});
while(!PQ.empty()){
auto [d,u,f]=PQ.top();PQ.pop();
if(dis[u][f]<d) continue;
for(auto [to,co]:G[u]){
if(chmin(dis[to][f],d+co)) PQ.push({d+co,to,f});
}
if(f==0&&OK[u]&&d<S+E){
chmax(d,S);
if(chmin(dis[u][1],d+1)) PQ.push({d+1,u,1});
}
}
if(dis[N-1][1]==INF) cout<<-1<<endl;
else cout<<dis[N-1][1]<<endl;
}
Rubikun