답안 #71973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71973 2018-08-26T04:26:24 Z Lawali(#2160, kig9981) 갈라파고스 여행 (FXCUP3_island) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> adj[300000], parent, select;
queue<int> Q;

void dfs(int c)
{
	bool leaf = true;
	for (auto n : adj[c]) {
		if (n != parent[c]) {
			parent[n] = c;
			dfs(n);
			leaf = false;
		}
	}
	if (leaf) Q.push(leaf);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	int N;
	vector<int> ans;
	cin >> N;
	parent.resize(N, -1);
	select.resize(N, -1);
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		adj[--a].push_back(--b);
		adj[b].push_back(a);
	}
	parent[0] = 0;
	dfs(0);
	while (!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if (c == 0 || select[c] != -1 || select[parent[c]] != -1) continue;
		select[c] = parent[c];
		select[parent[c]] = c;
		Q.push(parent[parent[c]]);
	}
	for (int i = 0; i < N; i++) {
		if (select[i] != -1 && i < select[i]) {
			if (ans.empty() || parent[ans.back()] != i && parent[i] != ans.back()) {
				ans.push_back(i);
				ans.push_back(select[i]);
			}
			else {
				ans.push_back(select[i]);
				ans.push_back(i);
			}
		}
	}
	if (ans.size() <= 2) {
		cout << "0\n";
	}
	else {
		if (!ans.empty()) ans.push_back(ans[0]);
		reverse(ans.begin(), ans.end());
		cout << ans.size() << '\n';
		for (auto a : ans) {
			cout << a << ' ';
		}
		cout << '\n';
	}
	return 0;
}

Compilation message

island.cpp:11:34: error: 'std::vector<int> select' redeclared as different kind of symbol
 vector<int> adj[300000], parent, select;
                                  ^~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:219:0,
                 from /usr/include/stdlib.h:314,
                 from /usr/include/c++/7/bits/std_abs.h:38,
                 from /usr/include/c++/7/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from island.cpp:1:
/usr/include/x86_64-linux-gnu/sys/select.h:106:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
 extern int select (int __nfds, fd_set *__restrict __readfds,
            ^~~~~~
island.cpp: In function 'int main()':
island.cpp:37:9: error: request for member 'resize' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
  select.resize(N, -1);
         ^~~~~~
island.cpp:49:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   if (c == 0 || select[c] != -1 || select[parent[c]] != -1) continue;
                         ^
island.cpp:49:31: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if (c == 0 || select[c] != -1 || select[parent[c]] != -1) continue;
                               ^
island.cpp:49:52: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   if (c == 0 || select[c] != -1 || select[parent[c]] != -1) continue;
                                                    ^
island.cpp:49:58: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if (c == 0 || select[c] != -1 || select[parent[c]] != -1) continue;
                                                          ^
island.cpp:50:11: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   select[c] = parent[c];
           ^
island.cpp:50:23: error: assignment of read-only location '*(select + ((sizetype)c))'
   select[c] = parent[c];
                       ^
island.cpp:50:23: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'int(int, fd_set*, fd_set*, fd_set*, timeval*)' in assignment
island.cpp:51:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   select[parent[c]] = c;
                   ^
island.cpp:51:23: error: assignment of read-only location '*(select + ((sizetype)parent.std::vector<int>::operator[](((std::vector<int>::size_type)c))))'
   select[parent[c]] = c;
                       ^
island.cpp:51:23: error: cannot convert 'int' to 'int(int, fd_set*, fd_set*, fd_set*, timeval*)' in assignment
island.cpp:55:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   if (select[i] != -1 && i < select[i]) {
               ^
island.cpp:55:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if (select[i] != -1 && i < select[i]) {
                     ^
island.cpp:55:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   if (select[i] != -1 && i < select[i]) {
                                      ^
island.cpp:55:38: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
island.cpp:56:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if (ans.empty() || parent[ans.back()] != i && parent[i] != ans.back()) {
island.cpp:58:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
     ans.push_back(select[i]);
                           ^
island.cpp:58:28: error: no matching function for call to 'push_back(int (&)(int, fd_set*, fd_set*, fd_set*, timeval*))'
     ans.push_back(select[i]);
                            ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from island.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near match>
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   conversion of argument 1 would be ill-formed:
island.cpp:58:27: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'std::vector<int>::value_type {aka int}' [-fpermissive]
     ans.push_back(select[i]);
                   ~~~~~~~~^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from island.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near match>
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   conversion of argument 1 would be ill-formed:
island.cpp:58:27: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'std::vector<int>::value_type {aka int}' [-fpermissive]
     ans.push_back(select[i]);
                   ~~~~~~~~^
island.cpp:61:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
     ans.push_back(select[i]);
                           ^
island.cpp:61:28: error: no matching function for call to 'push_back(int (&)(int, fd_set*, fd_set*, fd_set*, timeval*))'
     ans.push_back(select[i]);
                            ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from island.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near match>
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   conversion of argument 1 would be ill-formed:
island.cpp:61:27: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'std::vector<int>::value_type {aka int}' [-fpermissive]
     ans.push_back(select[i]);
                   ~~~~~~~~^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from island.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near match>
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   conversion of argument 1 would be ill-formed:
island.cpp:61:27: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'std::vector<int>::value_type {aka int}' [-fpermissive]
     ans.push_back(select[i]);
                   ~~~~~~~~^