Submission #829582

# Submission time Handle Problem Language Result Execution time Memory
829582 2023-08-18T13:05:09 Z faruk Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
190 ms 22392 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
#include <algorithm>
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int n;
bool check_components(vector<vector<int> > p) {
	vector<int> comp(n, -1);
	for (int i = 0; i < n; i++) {
		if (p[i][i] != 1)
			return false;
		if (comp[i] == -1) {
			for (int j = 0; j < n; j++) {
				if (p[i][j] != 0 and comp[j] != -1)
					return false;
				if (p[i][j] != 0)
					comp[j] = i;
			}
		}
		else {
			for (int j = 0; j < n; j++)
				if (p[i][j] != 0 and comp[j] != comp[i])
					return false;
		}
	}
	return true;
}

int construct(std::vector<std::vector<int>> p) {
	n = p.size();
	std::vector<std::vector<int>> answer;
	if (check_components(p) == false)
		return 0;
	vector<bool> visited(n);
	vector<vector<int> > out(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		if (visited[i])
			continue;
		vector<int> mine;
		for (int j = 0; j < n; j++)
			if (p[i][j] != 0)
				mine.push_back(j), visited[j] = true;
		if (mine.size() == 1)
			continue;

		vector<int> all2, everyone_else;
		for (int a : mine) {
			bool has1 = false;
			for (int j : mine)
				if (p[a][j] == 1 and j != a)
					has1 = true;
			if (has1)
				everyone_else.push_back(a);
			else
				all2.push_back(a);
		}
		for (int a : everyone_else) {
			for (int b : all2)
				if (p[a][b] != 2)
					return 0;
			for (int b : everyone_else)
				if (p[a][b] != 1)
					return 0;
		}

		if (everyone_else.size() == 0) { // cycle
			if (all2.size() <= 2)
				return 0;
			for (int i = 0; i < all2.size(); i++)
			{
				int f = all2[i], s = i < (all2.size() - 1) ? all2[i + 1] : all2[0];
				out[f][s] = 1, out[s][f] = 1;
			}
		}
		else if (all2.size() == 0) {// line
			for (int i = 0; i < everyone_else.size() - 1; i++)
			{
				int f = everyone_else[i], s = everyone_else[i + 1];
				out[f][s] = 1, out[s][f] = 1;
			}
		}
		else {
			// made cycle chain
			for (int i = 0; i < all2.size() - 1; i++)
			{
				int f = all2[i], s = all2[i + 1];
				out[f][s] = 1, out[s][f] = 1;
			}
			if (all2.size() == 1)
				return 0;

			// made one chain
			for (int i = 0; i < everyone_else.size() - 1; i++)
			{
				int f = everyone_else[i], s = everyone_else[i + 1];
				out[f][s] = 1, out[s][f] = 1;
			}

			int A = everyone_else[0], B = all2[0], C = all2.back();
			out[A][B] = 1;
			out[B][A] = 1;
			out[A][C] = 1;
			out[C][A] = 1;
		}
	}
	build(out);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |    for (int i = 0; i < all2.size(); i++)
      |                    ~~^~~~~~~~~~~~~
supertrees.cpp:78:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     int f = all2[i], s = i < (all2.size() - 1) ? all2[i + 1] : all2[0];
      |                          ~~^~~~~~~~~~~~~~~~~~~
supertrees.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    for (int i = 0; i < everyone_else.size() - 1; i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |    for (int i = 0; i < all2.size() - 1; i++)
      |                    ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:100:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |    for (int i = 0; i < everyone_else.size() - 1; i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 149 ms 22292 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 149 ms 22292 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 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 152 ms 22304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 820 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 55 ms 5988 KB Output is correct
21 Correct 153 ms 22304 KB Output is correct
22 Correct 190 ms 22392 KB Output is correct
23 Correct 176 ms 22300 KB Output is correct
24 Correct 157 ms 22304 KB Output is correct
25 Correct 80 ms 12352 KB Output is correct
26 Correct 66 ms 12324 KB Output is correct
27 Correct 155 ms 22240 KB Output is correct
28 Correct 168 ms 22276 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 148 ms 22252 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 149 ms 22216 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 64 ms 12296 KB Output is correct
18 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 37 ms 5988 KB Output is correct
5 Correct 155 ms 22288 KB Output is correct
6 Correct 152 ms 22228 KB Output is correct
7 Correct 169 ms 22264 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 37 ms 5944 KB Output is correct
10 Correct 158 ms 22336 KB Output is correct
11 Correct 156 ms 22208 KB Output is correct
12 Correct 164 ms 22232 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 284 KB Output is correct
16 Incorrect 22 ms 3464 KB Answer gives possible 0 while actual possible 1
17 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 149 ms 22292 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 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 152 ms 22304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 820 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 55 ms 5988 KB Output is correct
21 Correct 153 ms 22304 KB Output is correct
22 Correct 190 ms 22392 KB Output is correct
23 Correct 176 ms 22300 KB Output is correct
24 Correct 157 ms 22304 KB Output is correct
25 Correct 80 ms 12352 KB Output is correct
26 Correct 66 ms 12324 KB Output is correct
27 Correct 155 ms 22240 KB Output is correct
28 Correct 168 ms 22276 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 296 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 148 ms 22252 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 149 ms 22216 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 3 ms 796 KB Output is correct
45 Correct 64 ms 12296 KB Output is correct
46 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
47 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 149 ms 22292 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 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 152 ms 22304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 820 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 55 ms 5988 KB Output is correct
21 Correct 153 ms 22304 KB Output is correct
22 Correct 190 ms 22392 KB Output is correct
23 Correct 176 ms 22300 KB Output is correct
24 Correct 157 ms 22304 KB Output is correct
25 Correct 80 ms 12352 KB Output is correct
26 Correct 66 ms 12324 KB Output is correct
27 Correct 155 ms 22240 KB Output is correct
28 Correct 168 ms 22276 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 296 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 148 ms 22252 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 149 ms 22216 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 3 ms 796 KB Output is correct
45 Correct 64 ms 12296 KB Output is correct
46 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
47 Halted 0 ms 0 KB -