Submission #403749

#TimeUsernameProblemLanguageResultExecution timeMemory
403749salehPotemkin cycle (CEOI15_indcyc)C++17
20 / 100
20 ms2064 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 3, MAXM = 100 * 1000 + 23; /* 10 11 1 6 6 7 7 8 8 9 8 10 1 2 1 3 2 3 4 3 5 2 4 5 */ int n, m, h[MAXN], inv[MAXN]; vector<int> g[MAXN], vec, fen[MAXN]; bitset<MAXN> mark; void add(int p, int val) { for (p++; p; p -= (p & -p)) { int tmp = fen[p].back(); fen[p].push_back(max(val, tmp)); } } int get(int p) { int res = -1; for (p++; p < MAXN; p += (p & -p)) res = max(res, fen[p].back()); return res; } void undo(int p) { for (p++; p; p -= (p & -p)) fen[p].pop_back(); } void dfs(int v = 0, int p = -1) {//toghe va yal tekrari?? inv[v] = vec.size(); vec.push_back(v); mark[v] = true; if (vec.size() > 3) { int lw = -1; for (auto u : g[v]) if (u != p) if (mark[u]) { if (u == vec[vec.size() - 3]) { lw = -2; break; } if (lw == -1 || h[lw] < h[u]) lw = u; } if (lw > -1) { int x = get(inv[lw]);// if (x < h[lw]) { while (vec.back() != lw) { cout << vec.back() + 1 << ' '; vec.pop_back(); } cout << lw + 1 << ' '; exit(0); } } if (lw == -2) lw = vec[vec.size() - 3]; add(inv[v], h[lw]); } for (auto u : g[v]) if (!mark[u]) { h[u] = h[v] + 1; dfs(u, v); } if (vec.size() > 3) undo(inv[v]); vec.pop_back(); } int main() { for (int i = 0; i < MAXN; i++) fen[i].push_back(-1); ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[--a].push_back(--b), g[b].push_back(a); } dfs(); 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...