답안 #147232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147232 2019-08-28T12:59:51 Z luciocf Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
1000 ms 5624 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e3+10;

int mat[maxn][maxn];

int pai[maxn];
int dist[maxn];

bool nope[maxn];

vector<int> 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 v: grafo[u])
		{
			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);
		grafo[v].push_back(u);
	}

	for (int u = 1; u <= n; u++)
	{
		for (auto v: grafo[u])
		{
			memset(nope, 0, sizeof nope);

			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:45: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:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 12 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1664 KB Output is correct
2 Correct 4 ms 1560 KB Output is correct
3 Correct 5 ms 1656 KB Output is correct
4 Correct 154 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1656 KB Output is correct
2 Correct 92 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 5260 KB Output is correct
2 Correct 35 ms 4848 KB Output is correct
3 Execution timed out 1076 ms 5240 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4728 KB Output is correct
2 Execution timed out 1064 ms 4728 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 3704 KB Output is correct
2 Correct 530 ms 3832 KB Output is correct
3 Correct 316 ms 5496 KB Output is correct
4 Execution timed out 1080 ms 5624 KB Time limit exceeded