Submission #674071

#TimeUsernameProblemLanguageResultExecution timeMemory
674071US3RN4M3Thousands Islands (IOI22_islands)C++17
11.90 / 100
52 ms18188 KiB
#include"islands.h" #include<vector> #include<algorithm> #include<iostream> using namespace std; using ll = long long; const int mx = 200005; vector<pair<int, int>> fwd[mx]; vector<pair<int, int>> bck[mx]; int vis[mx]; bool is_cycle[mx]; int N; int bit; bool toggle; bool has_cycle(int cur) { vis[cur] = 1; for(auto [nxt, id] : fwd[cur]) { if(cur == 0) { if(toggle) { if((id >> bit) & 1) continue; } else { if(!((id >> bit) & 1)) continue; } } if(vis[nxt] == 0) { if(has_cycle(nxt)) return true; } else if(vis[nxt] == 1) { return true; } } vis[cur] = 2; return false; } std::variant<bool, std::vector<int>> find_journey(int _N, int M, std::vector<int> U, std::vector<int> V) { N = _N; for(int i = 0; i < N; i++) { fwd[i].clear(); bck[i].clear(); vis[i] = 0; } for(int i = 0; i < M; i++) { fwd[U[i]].push_back({V[i], i}); bck[V[i]].push_back({U[i], i}); } for(bit = 0; bit < 20; bit++) { for(int i = 0; i < N; i++) vis[i] = 0; toggle = false; if(!has_cycle(0)) continue; for(int i = 0; i < N; i++) vis[i] = 0; toggle = true; if(!has_cycle(0)) continue; return vector<int>(1, 2); } return false; }
#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...