제출 #1235688

#제출 시각아이디문제언어결과실행 시간메모리
1235688MuhammadSaramThousands Islands (IOI22_islands)C++20
컴파일 에러
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>

using namespace std;

const int M = 1000;

vector<int> nei[M],ans;
int vis[M], par[M], id[M];

void dfs(int u)
{
	vis[u]=1;
	if (ans.size())
	{
		vis[u]=2;
		return;
	}
	for (auto [i,x]:nei[u])
		if (!vis[i])
			par[i]=u,id[i]=x,dfs(i);
		else if(vis[i]==1)
		{
			int v=u;
			while (v)
				ans.push_back(id[v]),v=par[v];
			reverse(ans.begin(),ans.end());
			ans.push_back(x);
			int m=ans.size();
			for (int o=0;o<m;o++)
			{
				if (ans[o]==id[i])
				{
					for (int j=o+1;j<m;j++)
						ans.push_back(ans[j]+1);
					for (int j=m-1;j>o;j--)
						ans.push_back(ans[j]);
					for (int j=m-1;j>o;j--)
						ans.push_back(ans[j]+1);
					for (int j=o;j>=0;j--)
						ans.push_back(ans[j]);
					break;
				}
			}
			break;
		}
	vis[u]=2;
}

variant<bool, vector<int>> find_journey(int n, int m, vector<int> U, vector<int> V)
{
	for (int i=0;i<m;i+=2)
		nei[U[i]].push_back({V[i],i});
	dfs(0);
	if (ans.size()) return ans;
	return false;
}

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In function 'void dfs(int)':
islands.cpp:19:19: error: cannot decompose non-array non-class type 'int'
   19 |         for (auto [i,x]:nei[u])
      |                   ^~~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:53:36: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   53 |                 nei[U[i]].push_back({V[i],i});
      |                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187: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]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203: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]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~