10695 | 2024-04-09 21:07:42 | 111 | Rendőrségi őrjárat 2 | cpp17 | Accepted 100/100 | 78ms | 44504 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,L;
cin>>N>>M>>L;
vector<vector<int>>g(N);
for(int i=0;i<M;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int>v(N,-1);
for(int i=0;i<L;i++){
int c;
cin>>c;
v[c]=i;
}
vector<int>d(N,N*2);
priority_queue<pair<int,int>>q;
d[0]=0;
q.emplace(0,0);
while(!q.empty()){
auto[c,i]=q.top();
q.pop();
c*=-1;
if(c!=d[i]){
continue;
}
for(int j:g[i]){
int dd=c+1;
if(v[j]==dd%L){
dd++;
}
if(dd<d[j]){
d[j]=dd;
q.emplace(-dd,j);
}
}
}
cout<<d[N-1]<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 30/30 | ||||||
3 | Accepted | 3ms | 2488 KiB | ||||
4 | Accepted | 3ms | 2700 KiB | ||||
5 | Accepted | 3ms | 2932 KiB | ||||
6 | Accepted | 3ms | 3048 KiB | ||||
7 | Accepted | 3ms | 3072 KiB | ||||
8 | Accepted | 3ms | 3268 KiB | ||||
9 | Accepted | 3ms | 3464 KiB | ||||
subtask3 | 30/30 | ||||||
10 | Accepted | 56ms | 18572 KiB | ||||
11 | Accepted | 56ms | 20044 KiB | ||||
12 | Accepted | 57ms | 21532 KiB | ||||
13 | Accepted | 59ms | 23276 KiB | ||||
14 | Accepted | 61ms | 24828 KiB | ||||
subtask4 | 40/40 | ||||||
15 | Accepted | 76ms | 27436 KiB | ||||
16 | Accepted | 78ms | 28948 KiB | ||||
17 | Accepted | 70ms | 29272 KiB | ||||
18 | Accepted | 71ms | 30824 KiB | ||||
19 | Accepted | 71ms | 32360 KiB | ||||
20 | Accepted | 75ms | 34200 KiB | ||||
21 | Accepted | 74ms | 35740 KiB | ||||
22 | Accepted | 75ms | 37508 KiB | ||||
23 | Accepted | 70ms | 44504 KiB | ||||
24 | Accepted | 61ms | 40228 KiB |