Submission #1059639

#TimeUsernameProblemLanguageResultExecution timeMemory
1059639shiomusubi496Thousands Islands (IOI22_islands)C++17
11.90 / 100
24 ms7764 KiB
#include "islands.h" #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i) #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) using namespace std; using ll = long long; template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; } template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; } struct edge { int to, idx; }; using Graph = vector<vector<edge>>; std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { Graph G(N); rep (i, M) G[U[i]].push_back({V[i], i}); queue<int> que; vector<bool> seen(N, false), used(N, false); vector<bool> cycle1(N, false); que.push(0); while (!que.empty()) { int s = -1; bool flag = false; vector<int> cs; auto dfs = [&](auto&& self, int v) -> void { seen[v] = used[v] = true; for (auto e : G[v]) { if (used[e.to]) { if (s == -1) { s = e.to; cycle1[v] = true; cs.push_back(v); break; } else { flag = true; break; } } if (cycle1[e.to]) { flag = true; break; } if (seen[e.to]) continue; self(self, e.to); if (flag) break; if (s >= 0) { cycle1[v] = true; cs.push_back(v); if (s != v) break; s = -2; } } used[v] = false; }; int v = que.front(); que.pop(); dfs(dfs, v); if (flag) return true; for (int i : cs) cycle1[i] = false; for (int i : cs) if (i != cs.back()) que.push(i); } 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...