Submission #527675

#TimeUsernameProblemLanguageResultExecution timeMemory
527675siewjhPotemkin cycle (CEOI15_indcyc)C++17
100 / 100
286 ms94688 KiB
#include <iostream> #include <vector> #include <cstring> using namespace std; const int MAXN = 1005, MAXR = 200'005; int adjmat[MAXN][MAXN]; int vis[MAXR], p[MAXR]; pair<int, int> elist[MAXR]; vector<int> oadjlist[MAXN], adjlist[MAXR]; bool ans_found = 0; void dfs(int x, int par) { if (ans_found) return; vis[x] = 2; p[x] = par; for (int nxt : adjlist[x]) { if (!vis[nxt]) dfs(nxt, x); else if (vis[nxt] == 2 && !ans_found) { ans_found = 1; for (int curr = x; curr != nxt; curr = p[curr]) cout << elist[curr].first << ' '; cout << elist[nxt].first; } if (ans_found) return; } vis[x] = 1; // not useful anymore } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nodes, edges; cin >> nodes >> edges; memset(adjmat, -1, sizeof(adjmat)); for (int i = 0; i < edges; i++) { int a, b; cin >> a >> b; elist[i] = { a, b }; elist[i + edges] = { b, a }; adjmat[a][b] = i; adjmat[b][a] = i + edges; oadjlist[a].push_back(b); oadjlist[b].push_back(a); } for (int i = 1; i <= nodes; i++) { int sz = oadjlist[i].size(); for (int j = 0; j < sz; j++) for (int k = 0; k < j; k++) { int a = oadjlist[i][j], b = oadjlist[i][k]; if (adjmat[a][b] == -1) { adjlist[adjmat[a][i]].push_back(adjmat[i][b]); adjlist[adjmat[b][i]].push_back(adjmat[i][a]); } } } for (int i = 0; i < edges * 2; i++) if (!vis[i]) dfs(i, -1); if (!ans_found) cout << "no"; 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...