Submission #259993

#TimeUsernameProblemLanguageResultExecution timeMemory
259993Haunted_CppPotemkin cycle (CEOI15_indcyc)C++17
10 / 100
7 ms384 KiB
/** * author: Haunted_Cpp **/ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int MAX_N = 1e3 + 5; vector<vector<int>> g(MAX_N); bool vis[MAX_N]; deque<int> stk; int source; bool solve(int node) { vis[node] = true; stk.push_back(node); bool res = false; for (auto to : g[node]) { if (to == source) { // CHECK vector<int> cycle; for (auto cur : stk) { cycle.emplace_back(cur); } if ((int)cycle.size() < 4) { continue; } bool work = true; for (auto current : cycle) { int cnt = 0; for (auto nxt : cycle) { cnt += (find(g[current].begin(), g[current].end(), nxt) != g[current].end()); } work &= (cnt == 2); } res |= work; if (work) { for(auto ans : cycle) { cout << ans + 1 << ' '; } cout << '\n'; return true; } continue; } if (!vis[to]) { vis[to] = true; res |= solve(to); } } stk.pop_back(); vis[node] = false; return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; if (n > 10) { cout << "no" << '\n'; return 0; } for (int i = 0; i < m; i++) { int st, et; cin >> st >> et; --st; --et; g[st].emplace_back(et); g[et].emplace_back(st); } for (int i = 0; i < n; i++) { source = i; if(solve(i)) { memset(vis, false, sizeof(vis)); return 0; } } return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...