답안 #788274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788274 2023-07-20T04:27:05 Z mannshah1211 슈퍼트리 잇기 (IOI20_supertrees) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;



void build(vector<vector<int>> b);

struct DSU {
	vector<int> link, siz;
	DSU (int n) : link(n), siz(n, 1) {
		iota(link.begin(), link.end(), 0ll);
	}
	
	int get(int x) {
		if (link[x] == x) {
			return x;
		}
		return link[x] = get(link[x]);
	}
	
	bool unite(int a, int b) {
	   a = get(a), b = get(b);
	   if (a == b) {
	   	return false;
	   }
	   
	   if (siz[a] < siz[b]) {
	   	swap(a, b);
	   }
	   link[b] = a;
	   siz[a] += siz[b];
	   return true;
	}
	
	bool same(int a, int b) {
		return (get(a) == get(b));
	}
	
};

int construct(vector<vector<int>> p) {
	vector<vector<int>> b(p.size(), vector<int>(p.size()));
	DSU ds(n);
	for (int i = 0; i < p.size(); i++) {
		for (int j = i + 1; j < p.size(); j++) {
			if (p[i][j] != 0) {
				ds.unite(i, j);
			}
		}
	}
	
	for (int i = 0; i < p.size(); i++) {
		for (int j = i + 1; j < p.size(); j++) {
			if (p[i][j] == 0 && ds.same(i, j)) {
				return 0;
			} else if (p[i][j] == 1 && !ds.same(i, j)) {
				return 0;
			}
		}
	}
	
	vector<vector<int>> conncomps;
	for (int i = 0; i < p.size(); i++) {
		conncomps[ds.get(i)].push_back(i);
	}
	
	for (int i = 0; i < conncomps.size(); i++) {
		for (int j = 0; j < (int) conncomps[i].size() - 1; j++) {
			b[conncomps[i][j]][conncomps[i][j + 1]] = 1;
			b[conncomps[i][j + 1]][conncomps[i][j]] = 1;
		}
	}
	
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:44:9: error: 'n' was not declared in this scope
   44 |  DSU ds(n);
      |         ^
supertrees.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
supertrees.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for (int j = i + 1; j < p.size(); j++) {
      |                       ~~^~~~~~~~~~
supertrees.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
supertrees.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int j = i + 1; j < p.size(); j++) {
      |                       ~~^~~~~~~~~~
supertrees.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
supertrees.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i = 0; i < conncomps.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~