Submission #576135

#TimeUsernameProblemLanguageResultExecution timeMemory
576135VanillaConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int maxn = 1002;
int dsu[maxn];
set <int> comp [maxn];

int get_dad (int x) {
	return dsu[x] = (x == dsu[x] ? x: get_dad(dsu[x]));
}

void merge (int a, int b){
	a = get_dad(a);
	b = get_dad(b);
	dsu[b] = a;
}


int construct(vector<vector<int>> p) {
	int n = p.size();
	vector <vector <int> > b (n, vector <int> (n));
	for (int i = 0; i < n; i++){
		dsu[i] = i;
		comp[i].insert(i);
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < i; j++){
			if (p[i][j] != 0) merge(i,j);
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < i; j++){
			if (p[i][j] == 0 && get_dad(i) == get_dad(j)) return 0;
			if (get_dad(i) == get_dad(j)) comp[get_dad(i)].insert(j);
		}
	}
	for (int i = 0; i < n; i++){
		vector <int> v;
		for (int j: comp[i]) {
			v.push_back(j);
		}
		for (int j = 0; j < v.size(); j++){
			// cout << v[j] << " " << v[(j + 1) % v.size()] << "\n";
			b[v[j]][v[(j + 1) % v.size()]] = b[v[(j + 1) % v.size()]][v[j]] = 1;
		}
	}
	build(b);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int j = 0; j < v.size(); j++){
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...