Submission #115910

# Submission time Handle Problem Language Result Execution time Memory
115910 2019-06-09T16:27:07 Z tutis Potemkin cycle (CEOI15_indcyc) C++17
60 / 100
1000 ms 1408 KB
/*input
5 6
1 2
1 3
2 3
4 3
5 2
4 5

*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1010];
vector<int>x;
bitset<1010>yra;
bitset<1010>kaim[1010];
int pos[1010];
void ieskom(int i, int p)
{
	if (yra[i])
		return;
	pos[i] = x.size();
	x.push_back(i);
	yra[i] = true;
	int maxi = -1;
	auto xxx = (yra & kaim[i]);
	for (int j = xxx._Find_first(); j <= 1000; j = xxx._Find_next(j))
	{
		if (j != p)
		{
			maxi = max(maxi, pos[j]);
		}
	}
	if (maxi == -1)
	{
		for (int j : adj[i])
		{
			ieskom(j, i);
		}
	}
	else
	{
		vector<int>ciklas;
		for (int t = maxi; t < (int)x.size(); t++)
		{
			ciklas.push_back(x[t]);
		}
		if (ciklas.size() >= 4)
		{
			for (int i : ciklas)
				cout << i << " ";
			exit(0);
		}
	}
	yra[i] = false;
	x.pop_back();
}
int pa[1010];
int root(int x)
{
	if (pa[x] == x)
		return x;
	return pa[x] = root(pa[x]);
}
int main()
{
	srand(clock());
	ios_base::sync_with_stdio(false);
	int n, r;
	cin >> n >> r;
	for (int i = 1; i <= n; i++)
		pa[i] = i;
	while (r--)
	{
		int a, b;
		cin >> a >> b;
		kaim[a][b] = true;
		kaim[b][a] = true;
		adj[a].push_back(b);
		adj[b].push_back(a);
		pa[root(a)] = root(b);
	}
	vector<int>k[n + 1];
	for (int i = 1; i <= n; i++)
		k[root(i)].push_back(i);
	for (int i = 1; i <= n; i++)
	{
		if (k[i].empty())
			continue;
		for (int t = 0; t < 3; t++)
		{
			int j = k[i][rand() % k[i].size()];
			ieskom(j, -3);
		}
	}
	cout << "no\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 21 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 512 KB Output is correct
2 Correct 201 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 768 KB Output is correct
2 Execution timed out 1070 ms 768 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 1408 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -