This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int l;
int n,m;
int mp(int c,int x){
return (n*x+c);
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
vector<pair<int,int> > e(m);
for(int i=0;i<m;i++) cin>>e[i].first>>e[i].second;
int k;cin>>k;
if(k>1) return 0;
cin>>l;
vector<int> node(l);
for(int i=0;i<l;i++) cin>>node[i];
vector<vector<int> > side(n*l);
for(int i=0;i<n;i++){
for(int j=0;j<l;j++){
side[mp(i,j)].push_back(mp(i,(j+1)%l));
}
}
for(auto p : e){
int a = p.first-1;
int b = p.second-1;
for(int j=0;j<l;j++){
side[mp(a,j)].push_back(mp(b,(j+1)%l));
side[mp(b,j)].push_back(mp(a,(j+1)%l));
}
}
vector<bool> vis(n*l);
for(int i=0;i<l;i++){
vis[mp(node[i]-1,i)]=1;
}
queue<pair<int,int> > q;
q.push({mp(0,0),0});
vis[0]=1;
while(q.size()) {
auto cur =q.front();
q.pop();
if((cur.first%n)==(n-1)){
cout<<cur.second<<"\n";
return 0;
}
for(auto i : side[cur.first]){
if(!vis[i]) {
vis[i]=1;
q.push({i,cur.second+1});
}
}
}
cout<<"impossible\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |