Submission #311542

# Submission time Handle Problem Language Result Execution time Memory
311542 2020-10-10T15:23:14 Z Kenzo_1114 Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
26 ms 1792 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1010;

int n, m, depth[MAXN], low[MAXN], par[MAXN];
vector<int> graph[MAXN], l[MAXN];
bool marc[MAXN];

void dfs(int v, int p)
{
	depth[v] = (v == p) ? 1 : depth[p] + 1;
	par[v] = p;

	for(int i = 0; i < (int) graph[v].size(); i++)
	{
		int u = graph[v][i];
		if(depth[u])
		{
			if(u != p && depth[v] > depth[u])	
			{
				low[v] = max(low[v], depth[u]);
				l[v].push_back(u);
			}
			continue;
		}

		dfs(u, v);
	}
}

int main ()
{
	scanf("%d %d", &n, &m);

	for(int i = 0, u, v; i < m; i++)
	{
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	dfs(1, 1);

//	for(int i = 1; i <= n; i++)
//		printf("i = %d  par = %d  depth = %d low = %d\n", i, par[i], depth[i], low[i]);

	vector<int> ans;
	for(int i = 1; i <= n; i++)
	{
		bool ok = false;
		for(int j = 0; j < l[i].size(); j++)
		{
			if(depth[l[i][j]] != low[i])	continue;

			int cur = i;
			ans.push_back(cur), marc[cur] = true;
			while(cur != l[i][j])
				cur = par[cur],	ans.push_back(cur), marc[cur] = true;

			cur = i;
			ok = true;
			while(cur != l[i][j])
			{
				cur = par[cur];
				if(cur == l[i][j])	break;
				for(int k = 0; k < l[cur].size(); k++)
					if(marc[l[cur][k]])	ok = false;
			}

			ok = ok && ((int) ans.size() >= 4);

			if(ok)	break;
				
			for(int k = 0; k < ans.size(); k++)	marc[ans[k]] = false;
			ans.clear();

		}

		if(ok)	break;
	}

	if(ans.empty())	printf("no\n");
	else	
	{
		for(int i = 0; i < (int) ans.size(); i++)	printf("%d ", ans[i]);
		printf("\n");
	}
}
/*

5 6
1 2
1 3
2 3
4 3
5 2
4 5

4 5
1 2
2 3
3 4
4 1
1 3

*/

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j = 0; j < l[i].size(); j++)
      |                  ~~^~~~~~~~~~~~~
indcyc.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int k = 0; k < l[cur].size(); k++)
      |                    ~~^~~~~~~~~~~~~~~
indcyc.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    for(int k = 0; k < ans.size(); k++) marc[ans[k]] = false;
      |                   ~~^~~~~~~~~~~~
indcyc.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 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 0 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 416 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Incorrect 1 ms 512 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1280 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 768 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1792 KB Output is correct
2 Correct 24 ms 1784 KB Output is correct
3 Incorrect 25 ms 1536 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -