Submission #859292

#TimeUsernameProblemLanguageResultExecution timeMemory
859292Muhammad_AneeqPotemkin cycle (CEOI15_indcyc)C++17
40 / 100
1083 ms1516 KiB
/* بسم الله الرحمن الرحيم Author: (:Muhammad Aneeq:) */ #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <iostream> #include <vector> #include <set> #include <algorithm> #include <map> using namespace std; int const N=2000; vector<int>nei[N]={}; int vis[N]={}; vector<int>z; bool check(vector<int>g) { map<int,int>cnt; for (auto i:g) { for (auto j:nei[i]) cnt[j]++; } for (auto i:g) { if (cnt[i]!=2) return 0; } return 1; } void ans(vector<int>g) { reverse(g.begin(), g.end()); for (auto i:g) cout<<i<<' '; cout<<endl; _Exit(0); } void dfs(int x) { z.push_back(x); for (auto i:nei[x]) { if (vis[i]) { vector<int>g; for (int j=z.size()-1;j>=0;j--) { g.push_back(z[j]); if (z[j]==i) break; } if (g.size()>=4&&check(g)) ans(g); } else { vis[x]=1; dfs(i); vis[x]=0; } } if (z.size()) z.pop_back(); } inline void solve() { int n,m; cin>>n>>m; for(int i=1;i<=m;i++) { int a,b; cin>>a>>b; nei[a].push_back(b); nei[b].push_back(a); } vis[1]=1; dfs(1); cout<<"no\n"; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); solve(); }
#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...