Submission #52658

#TimeUsernameProblemLanguageResultExecution timeMemory
52658Alexa2001Potemkin cycle (CEOI15_indcyc)C++17
30 / 100
218 ms7156 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Nmax = 1005; bool edge[Nmax][Nmax], S[Nmax], used[Nmax]; int comp[Nmax], t[Nmax]; int x, y, n, m, i, C; vector<int> v[Nmax]; struct Forest { int t[2*Nmax]; void clear() { iota(t, t+2*n+1, 0); } int boss(int x) { if(t[x] == x) return x; return t[x] = boss(t[x]); } void unite(int x, int y) { x = boss(x), y = boss(y); if(x == y) return; t[x] = y; } } F; void dfs(int node) { used[node] = 1; comp[node] = C; for(auto it : v[node]) if(!used[it]) dfs(it); } void path(int start, int finish) { memset(t, -1, sizeof(t)); t[start] = 0; queue<int> q; q.push(start); int node; while(q.size() && t[finish] == -1) { node = q.front(); q.pop(); for(auto it : v[node]) if(t[it] == -1) { if(it == finish) { t[finish] = node; break; } else if(S[it]) continue; t[it] = node; q.push(it); } } assert(t[finish] != -1); while(finish) { cout << finish << ' '; finish = t[finish]; } } void solve() { int node, i; for(node = 1; node <= n; ++node) { memset(used, 0, sizeof(used)); memset(S, 0, sizeof(S)); memset(comp, 0, sizeof(comp)); for(auto it : v[node]) used[it] = 1, S[it] = 1; used[node] = 1, S[node] = 1; C = 0; for(i=1; i<=n; ++i) if(!used[i]) { ++C; dfs(i); } F.clear(); for(auto x : v[node]) for(auto y : v[x]) if(!S[y]) F.unite(x, n + comp[y]); for(auto x : v[node]) for(auto y : v[node]) if(x != y && !edge[x][y] && F.boss(x) == F.boss(y)) { path(x, y); cout << node << '\n'; return; } } cout << "no\n"; } int main() { // freopen("input", "r", stdin); // freopen("output", "w", stdout); cin.sync_with_stdio(false); cin >> n >> m; for(i=1; i<=m; ++i) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); edge[x][y] = edge[y][x] = 1; } solve(); 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...