Submission #147250

# Submission time Handle Problem Language Result Execution time Memory
147250 2019-08-28T13:53:07 Z luciocf Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
1000 ms 6904 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;
 
typedef pair<int, int> pii;

const int maxn = 1e3+10;
const int maxm = 1e5+10;
 
int mat[maxn][maxn];
 
int pai[maxn];
int dist[maxn];
 
bool nope[maxn];

pii edge[maxm];

vector<pii> grafo[maxn];
 
void bfs(int x, int nah)
{
	memset(dist, -1, sizeof dist);
 
	queue<int> fila;
 
	fila.push(x), dist[x] = 0, pai[x] = -1;
 
	while (!fila.empty())
	{
		int u = fila.front(); fila.pop();
 
		for (auto pp: grafo[u])
		{
			int v = pp.first;

			if (u == x && v == nah) continue;
			if (nope[v]) continue;
 
			if (dist[v] == -1)
			{
				dist[v] = dist[u]+1, pai[v] = u;
				fila.push(v);
			}
		}
	}
}
 
int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);
 
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
 
		mat[u][v] = mat[v][u] = 1;
 
		grafo[u].push_back({v, i});
		grafo[v].push_back({u, i});

		edge[i] = {u, v};
	}
 	
 	for (int i = 1; i <= m; i++)
 	{
		memset(nope, 0, sizeof nope);

		int u = edge[i].first, v = edge[i].second;

		for (int w = 1; w <= n; w++)
			if (w != u && w != v && mat[w][u] && mat[w][v])
				nope[w] = 1;

		bfs(u, v);

		if (dist[v] != -1)
		{
			while (v != u)
			{
				printf("%d ", v);
				v = pai[v];
			}

			printf("%d\n", u);

			return 0;
		}
	}
 
	printf("no\n");
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 12 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1784 KB Output is correct
2 Correct 4 ms 1656 KB Output is correct
3 Correct 5 ms 1784 KB Output is correct
4 Correct 83 ms 1844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1648 KB Output is correct
2 Correct 91 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 6008 KB Output is correct
2 Correct 62 ms 5112 KB Output is correct
3 Execution timed out 1071 ms 6036 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 393 ms 5188 KB Output is correct
2 Execution timed out 1087 ms 5112 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 72 ms 5496 KB Output is correct
2 Correct 287 ms 5596 KB Output is correct
3 Correct 146 ms 6904 KB Output is correct
4 Execution timed out 1075 ms 6772 KB Time limit exceeded