結果
| 問題 | No.2805 Go to School |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-20 12:52:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 2,000 ms |
| コード長 | 2,204 bytes |
| 記録 | |
| コンパイル時間 | 965 ms |
| コンパイル使用メモリ | 101,996 KB |
| 実行使用メモリ | 40,028 KB |
| 最終ジャッジ日時 | 2025-04-09 15:42:37 |
| 合計ジャッジ時間 | 5,441 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:77:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
77 | scanf("%d%d%d%d%d",&n,&m,&l,&s,&e);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:81:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
81 | scanf("%d%d%d",&i,&j,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:87:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
87 | scanf("%d",&i);
| ~~~~~^~~~~~~~~
ソースコード
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(i=0;i<(int)(n);i++)
#define NIL -1
using namespace std;
typedef long long ll;
typedef struct point{
int p;
ll t;
point(int pp=0,ll tt=0):p(pp),t(tt){}
}Point;
typedef struct data{
int p;
ll t;
bool tol;
data(int pp=0,ll tt=0,bool ttol=false):p(pp),t(tt),tol(ttol){}
bool operator<(const data& k)const{
return t<k.t;
}
}Data;
int n,m,l,s,e;
vector<vector<Point> > adj;
vector<bool> tol;
ll dijk(){
Data now,nxt;
vector<vector<bool> > visited(2,vector<bool>(n,false));
priority_queue<Data> PQ;
PQ.push(Data(0,0,false));
if(tol[0])
PQ.push(Data(0,-s-1,true));
while(PQ.size()){
do{
now=PQ.top();PQ.pop();
}while(PQ.size()&&visited[now.tol][now.p]);
if(visited[now.tol][now.p])
break;
//printf("now:(%d,%lld,%d)\n",now.p,-now.t,now.tol?1:0);
if(now.tol&&now.p==n-1)
return -now.t;
visited[now.tol][now.p]=true;
for(Point x:adj[now.p]){
nxt.p=x.p;
nxt.t=now.t-x.t;
nxt.tol=now.tol;
if(visited[nxt.tol][nxt.p]==false){
PQ.push(nxt);
//printf("new:(%d,%lld,%d)\n",nxt.p,-nxt.t,nxt.tol?1:0);
}
if(nxt.tol==false&&tol[nxt.p]){
nxt.tol=true;
if(s>-nxt.t){
nxt.t=-s-1;
}else if(-nxt.t<s+e){
nxt.t--;
}else
continue;
}
if(visited[nxt.tol][nxt.p]==false){
PQ.push(nxt);
//printf("new:(%d,%lld,%d)\n",nxt.p,-nxt.t,nxt.tol?1:0);
}
}
}
return NIL;
}
int main(){
int i,j,k;
scanf("%d%d%d%d%d",&n,&m,&l,&s,&e);
tol=vector<bool>(n,false);
adj=vector<vector<Point> >(n);
while(m--){
scanf("%d%d%d",&i,&j,&k);
i--;j--;
adj[i].push_back(Point(j,k));
adj[j].push_back(Point(i,k));
}
while(l--){
scanf("%d",&i);
i--;
tol[i]=true;
}
printf("%lld\n",dijk());
return 0;
}