Submission #598835

# Submission time Handle Problem Language Result Execution time Memory
598835 2022-07-19T06:15:09 Z 장태환(#8458) Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
18 ms 4112 KB
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
int num[1010];
int depth[1010];
int maxbe[1010];
int par[1010];
vector<int>link[1010];
bool arr[1010][1010];
vector<pair<int, int>>t;
int c;
void dfs(int n, int p = 0, int d = 0)
{
	depth[n] = d;
	num[n] = ++c;
	par[n] = p;
	int i;
	for (i = 0; i < link[n].size(); i++)
	{
		if (link[n][i] == p)
			continue;
		if (num[link[n][i]])
		{
			if (depth[link[n][i]] < d)
			{
				maxbe[n] = max(maxbe[n], depth[link[n][i]]);
				t.push_back({ n,link[n][i] });
			}
			else
			{
				maxbe[link[n][i]] = max(maxbe[link[n][i]], d);
				t.push_back({ link[n][i],n });
			}
		}
		else
		{
			dfs(link[n][i], n, d + 1);
		}
	}
}
int main()
{
	memset(maxbe, -10, sizeof(maxbe));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N, M;
	cin >> N >> M;
	int i;
	for (i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		link[a].push_back(b);
		link[b].push_back(a);
		arr[a][b] = arr[b][a] = true;
	}
	for (i = 1; i <= N; i++)
	{
		if (!num[i])
		{
			dfs(i);
		}
	}
	for (i = 0; i < t.size(); i++)
	{
		vector<int>ans;
		int c = 0;
		while (depth[t[i].first] > depth[t[i].second])
		{
			if (maxbe[t[i].first] > depth[t[i].second] || (maxbe[t[i].first] == depth[t[i].second] && c))
			{
				c = -1;
				break;
			}
			ans.push_back(t[i].first);
			t[i].first = par[t[i].first];
			c++;
		}
		if (c >= 0)
		{
			ans.push_back(t[i].second);
			if (ans.size() <= 3)
			{
				continue;
			}
			int j, k;
			for (j = 0; j < ans.size(); j++)
			{
				int k;
				for (k = j + 1; k <ans.size(); k++)
				{
					if (ans[j]==ans[k])
						assert(0);
				}
			}
			for (i = 0; i < ans.size(); i++)
				cout << ans[i] << ' ';
			return 0;
		}
	}
	cout << "no";
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int, int)':
indcyc.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (i = 0; i < link[n].size(); i++)
      |              ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (i = 0; i < t.size(); i++)
      |              ~~^~~~~~~~~~
indcyc.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for (j = 0; j < ans.size(); j++)
      |                ~~^~~~~~~~~~~~
indcyc.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for (k = j + 1; k <ans.size(); k++)
      |                     ~~^~~~~~~~~~~
indcyc.cpp:96:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |    for (i = 0; i < ans.size(); i++)
      |                ~~^~~~~~~~~~~~
indcyc.cpp:86:11: warning: unused variable 'k' [-Wunused-variable]
   86 |    int j, k;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Incorrect 2 ms 852 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3084 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2260 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4040 KB Output is correct
2 Correct 18 ms 4112 KB Output is correct
3 Incorrect 15 ms 3216 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -