Submission #1031557

# Submission time Handle Problem Language Result Execution time Memory
1031557 2024-07-23T00:54:03 Z aaaaaarroz Beech Tree (IOI23_beechtree) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> padre;
vector<int>sum;
bool orden(int x, int y){
	if (sum[x].size() != sum[y].size())
			return sum[x].size() < sum[y].size();
		return x > y;
}
vector<int> beechtree(int n, int m, vector<int>P, vector<int>C){
	vector<vector<int>> graph(n,vector<int>());
	padre = P;
	sum.resize(m,0);
	sum[C[0]]++;
	for(int i = 1; i < n; i++){
		graph[P[i]].push_back(i);
		sum[C[i]]++;
	}
	vector<int> ans(n, 0);
	for(int i = 0; i < n; i++){
		vector<int> sub;
		priority_queue<int,vector<int>,greater<int>> pila;
		pila.push(i);
		while(!pila.empty()){
			int nodo = pila.top(); 
			pila.pop();
			sub.push_back(nodo);
			for(int vecino : graph[nodo]){
				pila.push(vecino);
			} 
		}
		if(sub.size() == 1){
			ans[i] = 1;  
			continue;
		}
		sort(sub.begin()+1, sub.end(),orden);  
		bool bien = true;
		map<int, int> repeticiones;
		for(int j = 1; j < sub.size(); j++){
			int color = C[sub[j]];
			if(repeticiones.find(color) == repeticiones.end()){
				repeticiones[color] = 0;
			}
			int expected_parent = sub[repeticiones[color]]; 
			if(P[sub[j]] != expected_parent){
				bien = false;
				break;
			}
			repeticiones[color]++;
		}
		if(bien){
			ans[i] = 1;
		}
	}
	return ans;
}

Compilation message

beechtree.cpp: In function 'bool orden(int, int)':
beechtree.cpp:6:13: error: request for member 'size' in 'sum.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    6 |  if (sum[x].size() != sum[y].size())
      |             ^~~~
beechtree.cpp:6:30: error: request for member 'size' in 'sum.std::vector<int>::operator[](((std::vector<int>::size_type)y))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    6 |  if (sum[x].size() != sum[y].size())
      |                              ^~~~
beechtree.cpp:7:18: error: request for member 'size' in 'sum.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    7 |    return sum[x].size() < sum[y].size();
      |                  ^~~~
beechtree.cpp:7:34: error: request for member 'size' in 'sum.std::vector<int>::operator[](((std::vector<int>::size_type)y))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    7 |    return sum[x].size() < sum[y].size();
      |                                  ^~~~
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int j = 1; j < sub.size(); j++){
      |                  ~~^~~~~~~~~~~~