Submission #612870

# Submission time Handle Problem Language Result Execution time Memory
612870 2022-07-30T01:52:39 Z jairRS Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
279 ms 24060 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

struct DSU{
	vi p, s;
	DSU(int size){
		p = s = vi(size + 1, 1);
		for(int i = 0; i <= size; i++)
			p[i] = i;
	}

	int find(int x){
		if(p[x] == x)
			return x;
		return p[x] = find(p[x]);
	}

	void unite(int a, int b){
		a = find(a);
		b = find(b);
		if(a == b)
			return;
		if(s[a] > s[b])
			swap(a, b);
	
		s[b] += s[a];
		p[a] = b;
	}
};

int construct(vvi p) {
	int n = p.size();
	vvi answer = vvi(n, vi(n, 0));
	
	DSU dsu(n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if(p[i][j])
				dsu.unite(i, j);

	vvi group(n, vi());
	for (int i = 0; i < n; i++)
		group[dsu.find(i)].push_back(i);
	
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if(dsu.find(i) == dsu.find(j) && !p[i][j])
				return 0;
	
	for(vi & g : group)
		for (int i = 0; i + 1 < g.size(); i++)
		{
			answer[g[i]][g[i + 1]] = 1;
			answer[g[i + 1]][g[i]] = 1;
		}

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(vvi)':
supertrees.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int i = 0; i + 1 < g.size(); i++)
      |                   ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 1204 KB Output is correct
7 Correct 206 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 1204 KB Output is correct
7 Correct 206 ms 23924 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 8 ms 1248 KB Output is correct
13 Correct 206 ms 24052 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 83 ms 14064 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 59 ms 6188 KB Output is correct
21 Correct 197 ms 23916 KB Output is correct
22 Correct 206 ms 23924 KB Output is correct
23 Correct 190 ms 23936 KB Output is correct
24 Correct 249 ms 24052 KB Output is correct
25 Correct 93 ms 14080 KB Output is correct
26 Correct 91 ms 14064 KB Output is correct
27 Correct 264 ms 23920 KB Output is correct
28 Correct 279 ms 24060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 0 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 1204 KB Output is correct
7 Correct 206 ms 23924 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 8 ms 1248 KB Output is correct
13 Correct 206 ms 24052 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 83 ms 14064 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 59 ms 6188 KB Output is correct
21 Correct 197 ms 23916 KB Output is correct
22 Correct 206 ms 23924 KB Output is correct
23 Correct 190 ms 23936 KB Output is correct
24 Correct 249 ms 24052 KB Output is correct
25 Correct 93 ms 14080 KB Output is correct
26 Correct 91 ms 14064 KB Output is correct
27 Correct 264 ms 23920 KB Output is correct
28 Correct 279 ms 24060 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 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 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 1204 KB Output is correct
7 Correct 206 ms 23924 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 8 ms 1248 KB Output is correct
13 Correct 206 ms 24052 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 83 ms 14064 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 59 ms 6188 KB Output is correct
21 Correct 197 ms 23916 KB Output is correct
22 Correct 206 ms 23924 KB Output is correct
23 Correct 190 ms 23936 KB Output is correct
24 Correct 249 ms 24052 KB Output is correct
25 Correct 93 ms 14080 KB Output is correct
26 Correct 91 ms 14064 KB Output is correct
27 Correct 264 ms 23920 KB Output is correct
28 Correct 279 ms 24060 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -