답안 #800723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800723 2023-08-01T19:12:41 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_size(int v){
		return size[v];
	}
	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);
			
			done = true;
			parent[b] = a;
			size[a] += size[b];
		}
	}
};
int construct(vector<vi> p) {
	int n = p.size();
	vector<vi> answer(n, vi(n, 0));
	DSU dsu;
	dsu.init(n);
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(p[i][j] == 2)	dsu.merge(i, j)
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(dsu.find_parent(i) == dsu.find_parent(j) && p[i][j] == 0)	return 0;
		}
	}
	bool done[n];
	memset(done, false, sizeof done);
	for(int i = 0; i < n; i++){
		if(done[dsu.find_parent(i)])	continue;
		if(dsu.find_size(find_parent(i)) == 2)	return 0;
		done[dsu.find_parent(i)] = true;
		int first = -1, last = -1;
		for(int j = 0; j < n; j++){
			if(last == -1){
				last = j;
				first = j;
				continue;
			}
			if(dsu.find_parent(j) == dsu.find_parent(i)){
				answer[j][last] = 1;
				answer[last][j] = 1;
				last = j;
			}
		}
		answer[first][last] = 1;
		answer[last][first] = 1;
	}
	return 1;
}

Compilation message

supertrees.cpp: In member function 'void DSU::merge(int, int)':
supertrees.cpp:34:4: error: 'done' was not declared in this scope
   34 |    done = true;
      |    ^~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:36: error: expected ';' before '}' token
   47 |    if(p[i][j] == 2) dsu.merge(i, j)
      |                                    ^
      |                                    ;
   48 |   }
      |   ~                                 
supertrees.cpp:59:20: error: 'find_parent' was not declared in this scope
   59 |   if(dsu.find_size(find_parent(i)) == 2) return 0;
      |                    ^~~~~~~~~~~