답안 #794213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794213 2023-07-26T10:51:38 Z MODDI 슈퍼트리 잇기 (IOI20_supertrees) C++14
컴파일 오류
0 ms 0 KB
#include "supertrees.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
struct DSU{
	vi parent, size;
	void init(int n){
		for(int i = 0; i < n; i++){
			parent.pb(i);
			size.pb(1);
		}
	}
	int find_parent(int v){
		if(parent[v] == v)	return v;
		return parent[v] = find_parent(parent[v]);
	}
	void merge(int a, int b){
		a = find_parent(a);
		b = find_parent(b);
		if(a != b){
			if(size[b] > size[a])
				swap(a, b);
				
			parent[b] = a;
			size[a] += size[b];
		}
	}
};
int construct(vector<vi> p) {
	int n = p.size();
	vector<vi> answer;
	bool possible = true;
	for(int i = 0; i < n; i++){
		for(auto t : p[i]){
			if(t == 3)	possible = false;
		}
	}
	for(int i = 0; i < n; i++){
		vi pom(n,0);
		answer.pb(pom);
	}
	DSU dsu;
	dsu.init(n);
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(p[i][j] == 1){
				dsu.merge(i, j);
				dsu.merge(j, i);
			}
			else
				continue;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(p[i][j] == 0 && find_parent(i) == find_parent(j)){
				possible = false;
			}
		}
	}
	int last[n];
	memset(last, -1, sizeof last);
	for(int i = 0; i < n; i++){
		int a = dsu.find_parent(i);
		if(last[a] == -1)	last[a] = i;
		else{
			answer[i][last[a]] = 1;
			answer[last[a]][i] = 1;
			last[a] = i;
		}
	}
	if(!possible)	return 0;
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:63:23: error: 'find_parent' was not declared in this scope
   63 |    if(p[i][j] == 0 && find_parent(i) == find_parent(j)){
      |                       ^~~~~~~~~~~