답안 #598871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598871 2022-07-19T06:41:09 Z 장태환(#8458) Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
16 ms 3032 KB
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
int num[1010];
int depth[1010];
pair<int,int> maxbe[1010];
int par[1010];
vector<int>link[1010];
bool arr[1010][1010];
vector<pair<int, int>>t;
vector<int>ue[1010], de[1010];
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)
			{
				if (arr[n][link[n][i]])
					continue;
				arr[n][link[n][i]] = 1;
				maxbe[n] = max(maxbe[n], { depth[link[n][i]],link[n][i] });
				t.push_back({ n,link[n][i] });
			}
			else
			{
				if (arr[link[n][i]][n])
					continue;
				arr[link[n][i]][n] = 1;
				maxbe[link[n][i]] = max(maxbe[link[n][i]], { d,n });
				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);
	}
	for (i = 1; i <= N; i++)
	{
		if (!num[i])
		{
			dfs(i);
		}
	}
	for (i = 0; i < t.size(); i++)
	{
		vector<int>ans;
		int c = -1;
		ue[t[i].first].push_back(t[i].second);
		de[t[i].second].push_back(t[i].first);
		while (depth[t[i].first] > depth[t[i].second])
		{
			c++;
			ans.push_back(t[i].first);
			if (maxbe[t[i].first].first > depth[t[i].second] || (maxbe[t[i].first].first == depth[t[i].second] && c))
			{
				t[i].first = maxbe[t[i].first].second;
			}
			else
				t[i].first = par[t[i].first];
			c++;
		}
		ans.push_back(t[i].second);
		if (ans.size() <= 3)
		{
			continue;
		}
		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:19:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (i = 0; i < link[n].size(); i++)
      |              ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:50:34: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment [-Wclass-memaccess]
   50 |  memset(maxbe, -10, sizeof(maxbe));
      |                                  ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from indcyc.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
  211 |     struct pair
      |            ^~~~
indcyc.cpp:70: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]
   70 |  for (i = 0; i < t.size(); i++)
      |              ~~^~~~~~~~~~
indcyc.cpp:93:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (i = 0; i < ans.size(); i++)
      |               ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 852 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2628 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2024 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3032 KB Wrong adjacency
2 Halted 0 ms 0 KB -