Submission #819414

# Submission time Handle Problem Language Result Execution time Memory
819414 2023-08-10T10:37:22 Z Abrar_Al_Samit Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
191 ms 24084 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;


const int nax = 1000;

int par[nax], sz[nax];
vector<int>L[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);
		}
	}

	for(int i=0; i<n; ++i) {
		for(int j=0; j<n; ++j) if(!p[i][j]) {
			if(find(i) == find(j)) return 0;
		}
	}

	vector<vector<int>>ans(n, vector<int>(n));

	for(int i=0; i<n; ++i) if(i==find(i)) {
		if(sz[i]>1) {
			for(int x=0; x+1<sz[i]; ++x) {
				ans[L[i][x]][L[i][x+1]] = ans[L[i][x+1]][L[i][x]] = 1;
			}
			if(p[i][L[i][1]]==2) {
				ans[L[i][0]][L[i][sz[i]-1]] = ans[L[i][sz[i]-1]][L[i][0]] = 1;
			}
		} 
	}	
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1240 KB Output is correct
7 Correct 160 ms 24084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1240 KB Output is correct
7 Correct 160 ms 24084 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 157 ms 24004 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 10132 KB Output is correct
18 Correct 1 ms 264 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 6284 KB Output is correct
21 Correct 180 ms 23952 KB Output is correct
22 Correct 158 ms 23960 KB Output is correct
23 Correct 191 ms 23960 KB Output is correct
24 Correct 179 ms 24020 KB Output is correct
25 Correct 70 ms 10188 KB Output is correct
26 Correct 65 ms 10124 KB Output is correct
27 Correct 165 ms 24040 KB Output is correct
28 Correct 155 ms 23964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 40 ms 6272 KB Output is correct
5 Correct 159 ms 23964 KB Output is correct
6 Correct 160 ms 23956 KB Output is correct
7 Correct 177 ms 23968 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 40 ms 6208 KB Output is correct
10 Correct 159 ms 23968 KB Output is correct
11 Correct 155 ms 24032 KB Output is correct
12 Correct 164 ms 23952 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 332 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1240 KB Output is correct
7 Correct 160 ms 24084 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 157 ms 24004 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 10132 KB Output is correct
18 Correct 1 ms 264 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 6284 KB Output is correct
21 Correct 180 ms 23952 KB Output is correct
22 Correct 158 ms 23960 KB Output is correct
23 Correct 191 ms 23960 KB Output is correct
24 Correct 179 ms 24020 KB Output is correct
25 Correct 70 ms 10188 KB Output is correct
26 Correct 65 ms 10124 KB Output is correct
27 Correct 165 ms 24040 KB Output is correct
28 Correct 155 ms 23964 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1240 KB Output is correct
7 Correct 160 ms 24084 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 157 ms 24004 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 10132 KB Output is correct
18 Correct 1 ms 264 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 6284 KB Output is correct
21 Correct 180 ms 23952 KB Output is correct
22 Correct 158 ms 23960 KB Output is correct
23 Correct 191 ms 23960 KB Output is correct
24 Correct 179 ms 24020 KB Output is correct
25 Correct 70 ms 10188 KB Output is correct
26 Correct 65 ms 10124 KB Output is correct
27 Correct 165 ms 24040 KB Output is correct
28 Correct 155 ms 23964 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -