Submission #259990

#TimeUsernameProblemLanguageResultExecution timeMemory
259990Haunted_CppPotemkin cycle (CEOI15_indcyc)C++17
30 / 100
1096 ms2148 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) { //~ debug(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); } //~ cout << "YES" << '\n'; //~ debug(cycle); if ((int)cycle.size() < 4) { continue; } bool work = true; for (auto current : cycle) { int cnt = 0; //~ debug(current); for (auto nxt : cycle) { //~ debug(nxt); //~ debug(find(g[current].begin(), g[current].end(), nxt) != g[current].end()); cnt += (find(g[current].begin(), g[current].end(), nxt) != g[current].end()); } work &= (cnt == 2); //~ debug(cnt); } 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; 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); } //~ source = 1; //~ solve(1); for (int i = 0; i < n; i++) { source = i; if(solve(i)) { memset(vis, false, sizeof(vis)); return 0; } } cout << "no" << '\n'; 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...