제출 #1355313

#제출 시각아이디문제언어결과실행 시간메모리
1355313Charizard2021Connecting Supertrees (IOI20_supertrees)C++20
컴파일 에러
0 ms0 KiB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > adj;
vector<int> parent;
vector<bool> visited;
bool works = true;
int get(int a){
	if(parent[a] == a){
		return a;
	}
	int v = get(parent[a]);
	parent[a] = v;
	return v;
}
bool same_set(int a, int b){
	a = get(a);
	b = get(b);
	if(a == b){
		return true;
	}
	else{
		return false;
	}
}
bool join(int a, int b){
	a = get(a);
	b = get(b);
	if(a == b){
		return false;
	}
	if(sizes[a] < sizes[b]){
		swap(a, b);
	}
	sizes[a] += sizes[b];
	parent[b] = a;
	return true;
}
void dfs(int u, int p){
	visited[u] = true;
	for(int v = 0; v < n; v++){
		if(same_set(u, v) && p[u][v] == 0){
			works = false;
			return;
		}
		if(p[u][v] == 0){
			continue;
		}
		if(p[u][v] == 1 && same_set(u, v)){
			continue;
		}
		parent[v] = u;
		join(u, v);
		dfs(v, u);
		if(!works){
			return;
		}
	}
}
int construct(vector<vector<int> > p){
	n = p.size();
	adj.resize(n);
	visited.resize(n, false);
	parent.resize(n, -1);
	for(int i = 0; i < n; i++){
		if(!visited[i]){
			dfs(i, -1);
		}
	}
	if(works){
		vector<vector<int> > answer(n, vector<int>(n, 0));
		for(int i = 0; i < n; i++){
			if(parent[i] == -1) continue;
			answer[i][parent[i]] = 1;
			answer[parent[i]][i] = 1;
		}
		build(answer);
		return 1;
	}
	else{
		return 0;
	}
}

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

supertrees.cpp: In function 'bool join(int, int)':
supertrees.cpp:33:12: error: 'sizes' was not declared in this scope; did you mean 'size_t'?
   33 |         if(sizes[a] < sizes[b]){
      |            ^~~~~
      |            size_t
supertrees.cpp:36:9: error: 'sizes' was not declared in this scope; did you mean 'size_t'?
   36 |         sizes[a] += sizes[b];
      |         ^~~~~
      |         size_t
supertrees.cpp: In function 'void dfs(int, int)':
supertrees.cpp:43:39: error: invalid types 'int[int]' for array subscript
   43 |                 if(same_set(u, v) && p[u][v] == 0){
      |                                       ^
supertrees.cpp:47:21: error: invalid types 'int[int]' for array subscript
   47 |                 if(p[u][v] == 0){
      |                     ^
supertrees.cpp:50:21: error: invalid types 'int[int]' for array subscript
   50 |                 if(p[u][v] == 1 && same_set(u, v)){
      |                     ^