Submission #403749

# Submission time Handle Problem Language Result Execution time Memory
403749 2021-05-13T12:04:50 Z saleh Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
20 ms 2064 KB
#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 time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 396 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Incorrect 2 ms 460 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 952 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 588 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1308 KB Output is correct
2 Correct 20 ms 2064 KB Output is correct
3 Incorrect 18 ms 1624 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -