Submission #258157

#TimeUsernameProblemLanguageResultExecution timeMemory
258157dooweyPotemkin cycle (CEOI15_indcyc)C++14
30 / 100
222 ms1404 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1005; const int LOG = 14; vector<int> T[N]; bool vis[N]; int dep[N]; int cc; int par[N]; int high[N]; void dfs(int u, int pp){ par[u] = pp; vis[u]=true; for(auto x : T[u]){ if(x == pp){ continue; } if(vis[x]) { high[u] = max(high[u], dep[x]); continue; } dep[x]=dep[u]+1; dfs(x, u); } } int main(){ fastIO; int n, m; cin >> n >> m; int u, v; for(int i = 0 ; i < m ; i ++ ){ cin >> u >> v; T[u].push_back(v); T[v].push_back(u); } vector<int> pash; for(int i = 1; i <= n; i ++ ) pash.push_back(i); for(int it = 0; it < 200; it ++ ){ random_shuffle(pash.begin(), pash.end()); for(int j = 1; j <= n; j ++ ){ vis[j]=false; high[j]=-1; } for(auto i : pash ){ if(vis[i]) continue; dfs(i,i); } int node; bool good; for(int i = 1; i <= n; i ++ ){ for(auto x : T[i]){ if(dep[i] - dep[x] + 1 >= 4){ node = i; good = true; while(node != x){ if(node == i){ if(high[i] > dep[x]){ good = false; break; } } else if(high[node] >= dep[x]){ good = false; break; } node = par[node]; } if(good){ node = i; while(1){ cout << node << " "; if(node == x) break; node = par[node]; } 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...