#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define what_is(a) cout << #a << " is " <<a << "\n"
#define checker(a) cout << "chekcer reached " << a << "\n"
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
vector<vector<int>> adj(1000000,vector<int>());
struct node{
int n,t,a;
};
void print(node n){
cout << n.n << " " << n.t << " " << n.a << "\n";
}
void solve(){
int n,m;
cin >> n >> m;
for(int i=0;i<m;i++){
int u,v;
cin >>u >> v;
u--,v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
int k,l;
cin >> k;
assert(k==1);
cin >> l;
vector<int> w;
for(int i=0;i<l;i++){
int a;
cin >> a;
a--;
w.push_back(a);
}
int ans = -1;
queue<node> q;
q.push({0,0,0});
while(!q.empty()){
node u = q.front();
//print(u);
q.pop();
if(u.n==n-1){
ans = u.a;
break;
}
for(int v:adj[u.n]){
if(w[(u.t+1)%l]==v)continue;
if(w[(u.t+1)%l]==u.n&&w[(u.t)%l]==v)continue;
q.push({v,(u.t+1)%l,u.a+1});
}
if(w[(u.t+1)%l]!=u.n)
q.push({u.n,(u.t+1)%l,u.a+1});
}
cout << (ans==-1?"impossible":to_string(ans)) << " \n";
}
signed main(){
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
26560 KB |
Output is correct |
2 |
Runtime error |
1234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
26564 KB |
Output is correct |
2 |
Runtime error |
1192 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
26564 KB |
Output is correct |
2 |
Runtime error |
1192 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
26564 KB |
Output is correct |
2 |
Runtime error |
1192 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
26560 KB |
Output is correct |
2 |
Runtime error |
1234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
26560 KB |
Output is correct |
2 |
Runtime error |
1234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
26560 KB |
Output is correct |
2 |
Runtime error |
1234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |