제출 #1164557

#제출 시각아이디문제언어결과실행 시간메모리
1164557nai0610Beech Tree (IOI23_beechtree)C++20
컴파일 에러
0 ms0 KiB
#include "beechtree.h"
#include <bits/stdc++.h>
#define ll int64_t
#define ld long double
using namespace std;
// 
const int maxn =2e5+5;
const int mod = 1e9+7; // 998244353,1610612741
const ll inf = 1e18;
const ld pi = atan(1.0L)*4;
int sz[maxn],par[maxn],b[maxn],cnt[maxn],col[maxn];
vector<int> res[maxn];
bool vs[maxn];
vector<int> g[maxn];
struct nai{
	int s,id,u;
	bool operator<(const nai& other) const {
		return (s==other.s?id<other.id:s>other.s);
	}
};
int get(int u,int p=-1) {
	sz[u]=1;
	for (auto v:g[u]) {
		if (!vs[v]&&v!=p) sz[u]+=get(v,u);
	}
	return sz[u];
}
int find (int u,int s,int p=-1) {
	for (auto v:g[u]) {
		if (!vs[v]&&v!=p&&sz[v]*2>=s) return find(v,s,u);
	}
	return u;
}
int calc(int u){
	vector<int> a;
	set<nai> s;
	s.insert({sz[u],0,u});
	while (!s.empty()) {
		int x=s.begin()->u;
		s.erase(s.begin());
		a.push_back(x);
		for (auto v:g[x]) s.insert({sz[v],(int)a.size(),v});
	}
	for (int i=1;i<a.size();i++) {
		int x=(i==1?0:cnt[col[a[i]]]);
		if (par[a[i]]!=a[x]) return false;
		cnt[col[a[i]]]++;
	}
	return true;
}
void nai(int u) {
	int c=find(u,get(u));
	vs[c]=1;
	if (b[c]==-1){
		b[c]=calc(c);
		if (b[c]==0) {
			for (int v=par[c];v&&b[v]==-1;v=par[v]) b[v]=0;
		}
	}
	if (b[c]!=1) {
		for (auto v:g[c]) nai(v);
	}
	if (par[c]&&!vs[par[c]]) nai(par[c]);
}
vector<int> beechtree(int n,int m,vector<int> p,vector<int> c){
	for (int i=0;i<n;i++) {
		col[i+1]=c[i];
		par[i+1]=p[i]+1;
		g[par[i+1]].push_back(i+1);
	}
	memset(b,-1,sizeof(b));
	nai(1);
	for (int i=1;i<=n;i++) {
		if (b[i]==-1) b[i]=0;
		res[i-1]=b[i];
	}
	return res;
}

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

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:75:29: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
   75 |                 res[i-1]=b[i];
      |                             ^
In file included from /usr/include/c++/11/vector:72,
                 from beechtree.h:1,
                 from beechtree.cpp:1:
/usr/include/c++/11/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/11/vector:67,
                 from beechtree.h:1,
                 from beechtree.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
beechtree.cpp:77:16: error: could not convert 'res' from 'std::vector<int> [200005]' to 'std::vector<int>'
   77 |         return res;
      |                ^~~
      |                |
      |                std::vector<int> [200005]