Submission #819870

# Submission time Handle Problem Language Result Execution time Memory
819870 2023-08-10T14:46:32 Z Abrar_Al_Samit Connecting Supertrees (IOI20_supertrees) C++17
46 / 100
165 ms 24024 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);
		}
		if(heads.size()==1) continue;
		assert(heads.size()!=2);
		
		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:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i=0; i<heads.size(); ++i) {
      |                ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 7 ms 1232 KB Output is correct
7 Correct 158 ms 23952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 7 ms 1232 KB Output is correct
7 Correct 158 ms 23952 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 157 ms 23952 KB Output is correct
14 Runtime error 1 ms 468 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 39 ms 6280 KB Output is correct
5 Correct 154 ms 23996 KB Output is correct
6 Correct 157 ms 23960 KB Output is correct
7 Correct 161 ms 23960 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 39 ms 6264 KB Output is correct
10 Correct 155 ms 24004 KB Output is correct
11 Correct 154 ms 23960 KB Output is correct
12 Correct 165 ms 24000 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 6260 KB Output is correct
17 Correct 159 ms 24024 KB Output is correct
18 Correct 153 ms 24012 KB Output is correct
19 Correct 153 ms 23956 KB Output is correct
20 Correct 152 ms 23952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 7 ms 1232 KB Output is correct
7 Correct 158 ms 23952 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 157 ms 23952 KB Output is correct
14 Runtime error 1 ms 468 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 7 ms 1232 KB Output is correct
7 Correct 158 ms 23952 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 157 ms 23952 KB Output is correct
14 Runtime error 1 ms 468 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -