Submission #741758

# Submission time Handle Problem Language Result Execution time Memory
741758 2023-05-14T19:51:35 Z MODDI Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
int parent[1001], sz[1001];
void init(){
	for(int i = 0; i < 1000; i++){
		parent[i] = i;
		sz[i] = 1;
	}
}
int find(int v){
	if(parent[v] == v)	return v;
	return parent[v] = find(parent[v]);
}
void combine(int i, int j){
	i = find(i);
	j = find(j);
	if(i == j)	return;
	if(sz[i] < sz[j]) swap(i, j);
	parent[j] = i;
	sz[i] += sz[j];
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool one = true, two = true, lessTwo = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 3)	return 0;
			if(p[i][j]  != one)	one = false;
			if(p[i][j] == 2)	lessTwo = false;
		}
	}
	if(one){
		vector<vector<int>> b;
		for(int i = 0; i < n; i++){
			vi arr(n, 0);
			if(i >0)	arr[i-1]=1;
			if(i+1<n)	arr[i+1]=1;
			b.pb(arr);
		}
		build(b);	
		return 1;	
	}
	else if(lessTwo){
		init();
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				if(p[i][j] == 1){
					combine(i, j);
				}
			}
		}
		int last[n]; // for every branch;
		memset(last, -1, sizeof last);
		vector<vector<int> > b(n, vector<int>(n));
		for(int i = 0; i < n; i++){
			vi arr(n,0);
			for(int j = 0; j < n; j++){
				if(find(i) == find(j)){
					arr[i][j] = 1;
				}
			}
			b.pb(arr);
		}
		build(b);
		return 1;
	}
	return 0;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:66:12: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   66 |      arr[i][j] = 1;
      |            ^
supertrees.cpp:31:19: warning: unused variable 'two' [-Wunused-variable]
   31 |  bool one = true, two = true, lessTwo = true;
      |                   ^~~