Submission #315338

#TimeUsernameProblemLanguageResultExecution timeMemory
315338shivensinha4Potemkin cycle (CEOI15_indcyc)C++17
60 / 100
237 ms1936 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const int MXN = 1000; vi adj[MXN+1]; bool isAdj[MXN+1][MXN+1]; int pre[MXN+1]; int main() { #ifdef shiven freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for_(i, 0, m) { int a, b; cin >> a >> b; a -= 1; b -= 1; adj[a].push_back(b); adj[b].push_back(a); isAdj[a][b] = isAdj[b][a] = true; } vi ans; for_(p, 0, n) { memset(pre, -1, sizeof(pre)); queue<int> q; for (int a: adj[p]) if (pre[a] == -1) { pre[a] = a; q.push(a); while (q.size()) { int pp = q.front(); q.pop(); for (int i: adj[pp]) if (i != p and pre[i] == -1 and !(isAdj[i][a] and isAdj[i][p])) { pre[i] = pp; if (isAdj[i][p]) { int b = i; ans.push_back(b); while (b != a) ans.push_back(b = pre[b]); ans.push_back(p); for (int i: ans) cout << i+1 << " "; cout << endl; return 0; } q.push(i); } } } } cout << "no" << endl; 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...