Submission #441668

#TimeUsernameProblemLanguageResultExecution timeMemory
441668OzyFrom Hacks to Snitches (BOI21_watchmen)C++17
0 / 100
3185 ms106288 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define lli long long int #define MAX 100000 #define pos first #define tiempo second lli n,m,a,b,k,x,y,res; vector<lli> hijos[MAX+2],pos[127]; lli visitados[127][MAX+2],grupo[127],mod[127]; queue< pair<lli,lli> > cola; pair<lli,lli> act; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; rep(i,1,n) hijos[i].push_back(i); rep(i,1,m) { cin >> a >> b; hijos[a].push_back(b); hijos[b].push_back(a); } mod[0] = 125; cin >> k; rep(i,1,k) { cin >> mod[i]; rep(j,1,mod[i]) { cin >> b; grupo[b] = i; pos[i].push_back(b); } } cola.push({1,0}); res = -1; while (!cola.empty()) { act = cola.front(); cola.pop(); x = grupo[act.pos]; a = act.tiempo % mod[x]; if (visitados[a][act.pos] != 0) continue; if (act.pos == n) {res = act.tiempo; break;} visitados[a][act.pos] = 1; for (auto h : hijos[act.pos]){ y = grupo[h]; b = (act.tiempo+1) % mod[y]; if (!pos[y].empty() && pos[y][b] == h) continue; if (visitados[b][h] != 0) continue; if (y == x && y > 0) { if (pos[y][a] == h && pos[x][b] == act.pos) continue; } cola.push({h,act.tiempo+1}); } } if (res == -1) cout << "impossible"; else cout << res; }
#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...