제출 #1164552

#제출 시각아이디문제언어결과실행 시간메모리
1164552nai0610Beech 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> 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]);
}
int[] beechtree(int n,int m,int[] p,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;
	}
	return b;
}

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

beechtree.cpp: In function 'int get(int, int)':
beechtree.cpp:22:22: error: 'vs' was not declared in this scope; did you mean 'v'?
   22 |                 if (!vs[v]&&v!=p) sz[u]+=get(v,u);
      |                      ^~
      |                      v
beechtree.cpp: In function 'int find(int, int, int)':
beechtree.cpp:28:22: error: 'vs' was not declared in this scope; did you mean 'v'?
   28 |                 if (!vs[v]&&v!=p&&sz[v]*2>=s) return find(v,s,u);
      |                      ^~
      |                      v
beechtree.cpp: In function 'void nai(int)':
beechtree.cpp:51:9: error: 'vs' was not declared in this scope
   51 |         vs[c]=1;
      |         ^~
beechtree.cpp: At global scope:
beechtree.cpp:63:4: error: structured binding declaration cannot have type 'int'
   63 | int[] beechtree(int n,int m,int[] p,int[] c){
      |    ^~
beechtree.cpp:63:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
beechtree.cpp:63:4: error: empty structured binding declaration
beechtree.cpp:63:7: error: expected initializer before 'beechtree'
   63 | int[] beechtree(int n,int m,int[] p,int[] c){
      |       ^~~~~~~~~