Submission #819868

# Submission time Handle Problem Language Result Execution time Memory
819868 2023-08-10T14:45:06 Z Abrar_Al_Samit Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 340 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;


const int nax = 1000;

int par[nax], sz[nax];
vector<int>L[nax];
bool done[nax];

int find(int v) {
	return par[v] = (v == par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
	u = find(u), v = find(v);
	if(u==v) return;

	if(sz[u] < sz[v]) swap(u, v);

	for(int x : L[v]) {
		L[u].push_back(x);
	}
	sz[u] += sz[v];
	par[v] = u;
}
int construct(vector<vector<int>> p) {
	int n = p.size();

	for(int i=0; i<n; ++i) {
		par[i] = i, sz[i] = 1;
		L[i] = {i};
	}

	for(int i=0; i<n; ++i) {
		for(int j=0; j<n; ++j) if(p[i][j]) {
			unite(i, j);
		}
	}
	vector<vector<int>>ans(n, vector<int>(n));


	for(int i=0; i<n; ++i) if(i == find(i)) {
		vector<int>heads;
		for(int v : L[i]) if(!done[v]) {
			done[v] = true;
			for(int u=0; u<n; ++u) {
				if(p[u][v]==1 && u!=v) {
					ans[u][v] = ans[v][u] = 1;
					done[u] = true;
				}
			}
			heads.push_back(v);
		}
		for(int i=0; i<heads.size(); ++i) {
			int v = heads[i];
			int u = heads[(i+1)%heads.size()];
			ans[u][v] = ans[v][u] = 1;
		}
	}

	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i=0; i<heads.size(); ++i) {
      |                ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -