Submission #35996

#TimeUsernameProblemLanguageResultExecution timeMemory
35996funcsrPotemkin cycle (CEOI15_indcyc)C++14
50 / 100
1000 ms3004 KiB
#include <iostream> #include <fstream> #include <bitset> #include <cassert> #include <vector> #include <queue> #include <algorithm> #define rep(i, n) for (int i=0; i<(n); i++) #define INF 1145141919 #define all(x) x.begin(), x.end() #define pb push_back using namespace std; int N, M; bool G[1000][1000]; int A[1000], pre[1000]; int U[10]; bool used[10]; int find(int x) { if (U[x] == x) return x; return U[x] = find(U[x]); } void unite(int x, int y) { x = find(x), y = find(y); U[x] = y; } signed main() { cin >> N >> M; rep(i, M) { int a, b; cin >> a >> b; a--, b--; G[a][b] = G[b][a] = true; } rep(s, N) { rep(i, N) A[i] = -1; queue<int> q; rep(t, N) if (G[s][t]) { pre[t] = s; A[t] = t; q.push(t); } while (!q.empty()) { int x = q.front(); q.pop(); rep(t, N) if (G[x][t]) { if (t == s) continue; if (A[t] == -1) { A[t] = A[x], pre[t] = x; q.push(t); } else { int a = A[x], b = A[t]; if (a == b || G[a][b]) continue; vector<int> left, right; while (x != s) { left.pb(x); x = pre[x]; } while (t != s) { right.pb(t); t = pre[t]; } reverse(all(right)); left.pb(s); for (int r : right) left.pb(r); for (int x : left) cout << x+1 << " "; cout << "\n"; return 0; } } } } if (N <= 10) { rep(S, 1<<N) { if (__builtin_popcount(S) < 4) continue; rep(i, N) U[i] = i; bool ok = true; int hoe = -1; rep(i, N) { if (((S>>i)&1) == 0) continue; hoe = i; int deg = 0; rep(t, N) if (G[i][t] && (S>>t)&1) unite(i, t), deg++; if (deg != 2) { ok = false; break; } } rep(i, N) if ((S>>i)&1) if (find(hoe) != find(i)) ok = false; if (!ok) continue; vector<int> vs; int v = hoe; used[v] = true; vs.pb(v); while (true) { int to = -1; rep(t, N) if (G[v][t] && (S>>t)&1 && !used[t]) to = t; if (to == -1) break; used[to] = true; v = to; vs.pb(v); } assert(vs.size() == __builtin_popcount(S)); for (int x : vs)cout<<x+1<< " ";cout<<"\n"; 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...