Submission #527097

#TimeUsernameProblemLanguageResultExecution timeMemory
527097maomao90Potemkin cycle (CEOI15_indcyc)C++17
50 / 100
1086 ms6340 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i, j, k) for (int i = j; i < k; i++) #define RREP(i, j, k) for (int i = j; i >= k; i--) template<class T> inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;} template<class T> inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;} typedef long long ll; #define FI first #define SE second #define MP make_pair typedef pair<int, int> ii; #define pb push_back #define ALL(x) x.begin(), x.end() typedef vector<int> vi; typedef vector<ii> vii; #ifndef DEBUG #define cerr if (0) cerr #endif #define MAXN 1005 #define INF 1000000005 #define LINF 1000000000000000005ll int n, r; vi adj[MAXN]; int vis[MAXN], dist[MAXN], p[MAXN]; int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n >> r; REP (i, 0, r) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } REP (i, 1, n + 1) { set<ii> ban; queue<int> bfs; vis[i] = i; dist[i] = 0; bfs.push(i); cerr << i << '\n'; while (!bfs.empty()) { int u = bfs.front(); bfs.pop(); cerr << ' ' << u << '\n'; for (int v : adj[u]) { cerr << " " << v << '\n'; if (vis[v] == i) { if (v == p[u]) continue; if (dist[u] == 1 && dist[v] == 1) { ban.insert(MP(min(u, v), max(u, v))); continue; } assert(dist[u] + dist[v] + 1 > 3); vi ans; int x = v; int a1 = -1; while (x != i) { a1 = x; ans.pb(x); x = p[x]; } ans.pb(i); reverse(ALL(ans)); x = u; int a2 = -1; while (x != i) { a2 = x; ans.pb(x); x = p[x]; } if (ban.find(MP(min(a1, a2), max(a1, a2))) != ban.end()) { continue; } if (a1 == a2) { continue; } for (int a : ans) { cout << a << ' '; } cout << '\n'; return 0; } vis[v] = i; dist[v] = dist[u] + 1; p[v] = u; bfs.push(v); } } } 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...