Submission #563895

#TimeUsernameProblemLanguageResultExecution timeMemory
563895piOOEPotemkin cycle (CEOI15_indcyc)C++17
60 / 100
1091 ms2216 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define sz(x) ((int)size(x)) #define trace(x) cout << #x << ": " << (x) << endl; typedef long long ll; const int N = 1000; bool e[N][N]; int used[N]; vector<int> st; int n; vector<int> g[N]; void dfs(int v, int p, int d) { st.push_back(v); used[v] = d; int gg = -1; for (int to:g[v]) { if (to != p && used[to]) { if (gg == -1 || used[to] > used[gg]) { gg = to; } } } if (gg != -1) { cout << gg + 1 << " "; while (st.back() != gg) { cout << st.back() + 1 << " "; st.pop_back(); } exit(0); } for (int to: g[v]) { if (to != p && !e[p][to]) { dfs(to, v, d + 1); } } st.pop_back(); used[v] = false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int r; cin >> n >> r; for (int i = 0; i < r; ++i) { int a, b; cin >> a >> b; --a, --b; e[a][b] = e[b][a] = true; g[a].push_back(b); g[b].push_back(a); } for (int v = 0; v < n; ++v) { used[v] = true; st.push_back(v); for (int to: g[v]) { dfs(to, v, 2); } st.pop_back(); used[v] = false; } 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...