Submission #589428

#TimeUsernameProblemLanguageResultExecution timeMemory
589428BlagojcePotemkin cycle (CEOI15_indcyc)C++11
30 / 100
1124 ms900268 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define st first #define nd second #define pb push_back #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int mxn = 1003; mt19937 _rand(time(NULL)); clock_t z; int n, m; vector<int> g[mxn]; bool adj[mxn][mxn]; int vis[mxn]; bool deleted[mxn]; int uniq = 0; int aux[mxn]; int parent[mxn]; void expand(int r, int x, int y){ uniq ++; queue<int> Q; Q.push(x); vis[x] = uniq; vis[r] = uniq; parent[x] = x; while(!Q.empty()){ int c = Q.front(); Q.pop(); for(auto e : g[c]){ if(vis[e] == uniq) continue; vis[e] = uniq; parent[e] = c; Q.push(e); } } vector<int> sol; sol.pb(r); sol.pb(y); while(sol.back() != x){ sol.pb(parent[sol.back()]); } for(auto u : sol) cout<<u+1<<' '; cout<<endl; exit(0); } vector<int> check(vector<int> G, int r){ ++uniq; for(auto u : G){ aux[u] = uniq; } vector<int> S; for(auto u : g[r]){ if(deleted[u]) continue; for(auto e : g[u]){ if(deleted[e]) continue; if(aux[e] == uniq){ S.pb(u); break; } } } fr(i, 0, (int)S.size()){ fr(j, i+1, (int)S.size()){ if(!adj[S[i]][S[j]]){ expand(r, S[i], S[j]); } } } for(auto u : S) G.pb(u); return G; } vector<vector<int> > generate_next(vector<vector<int> > G, int r){ fr(i, 0, (int)G.size()){ G[i] = check(G[i], r); } vector<int> S; for(auto u : g[r]){ if(deleted[u]) continue; S.pb(u); } G.pb(S); return G; } vector<int> gp; void dfs(int u){ gp.pb(u); vis[u] = uniq; for(auto e : g[u]){ if(aux[e] != uniq || vis[e] == uniq) continue; dfs(e); } } vector<vector<int> > split(vector<int> v, int r){ ++uniq; for(auto u : v) aux[u] = uniq; vis[r] = uniq; for(auto u : g[r]) vis[u] = uniq; vector<vector<int> > G; for(auto u : v){ if(vis[u] == uniq) continue; gp.clear(); dfs(u); G.pb(gp); } return G; } void solve(vector<int> v){ if((int)v.size() < 4) return; int r = v[0]; vector<vector<int> > G = split(v, r); G = generate_next(G, r); for(auto Gp : G){ solve(Gp); } } int main(){ cin >> n >> m; fr(i, 0, m){ int u, v; cin >> u >> v; --u, --v; g[u].pb(v); g[v].pb(u); adj[u][v] = true; adj[v][u] = true; } vector<int> v; fr(i, 0, n) v.pb(i); solve(v); cout<<"no"<<endl; }
#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...