Submission #420349

#TimeUsernameProblemLanguageResultExecution timeMemory
420349lakshith_From Hacks to Snitches (BOI21_watchmen)C++14
0 / 100
1234 ms524292 KiB
#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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...