Submission #300281

# Submission time Handle Problem Language Result Execution time Memory
300281 2020-09-17T03:59:55 Z aljasdlas Connecting Supertrees (IOI20_supertrees) C++14
40 / 100
279 ms 30200 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

bool possible = true;
vector<vector<int>> b;
int n;
bitset<1005> vis;
bitset<1005> isOne;
vector<int> AdjList[1005];

vector<vector<int>> components;
int compNum[1005];
vector<vector<int>> p;

void dfs(int u) {
// << u << " ";
	vis[u] = 1;
	compNum[u] = components.size();
	components.back().push_back(u);
	for(auto &v: AdjList[u])
		if(!vis[v])
			dfs(v);
}


int construct(vector<vector<int>> p_) {
	p = p_;
	n = p.size();
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(p[i][j] != 0)
				AdjList[i].push_back(j);

	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		b.push_back(row);
	}

	vis.reset();

	for(int i = 0; i < n; i++)
		if(!vis[i]) {
			components.push_back(vector<int>(0));
		// << "Comp " << components.size() << ": ";
			dfs(i);
		// << endl;
		}

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(compNum[i] == compNum[j] && p[i][j] == 0)
				return 0;
			else if(compNum[i] != compNum[j] && p[i][j] > 0)
				return 0;

	for(auto &v: components) {
		isOne.reset();
		if(v.size() == 1)
			continue;
		for(auto &x: v) {
			for(auto &y: v) {
				if(x == y) continue;
				if(p[x][y] == 1)
					isOne[x]=isOne[y]=1;
			}
		}

		for(auto &x: v) {
			for(auto &y: v) {
				if(x == y) continue;
				if(isOne[x]) {
					if(isOne[y]) {
						if(p[x][y] != 1) return 0;
					}
				}
			}
		}

		vector<int> is[3];
		for(auto &x: v)
			if(isOne[x]) is[1].push_back(x);
			else is[2].push_back(x);
		
		
	// << "Is 1: "; for(auto x: is[1]) cerr << x << " "; cerr << endl;
	// << "Is 2: "; for(auto x: is[2]) cerr << x << " "; cerr << endl;

		if(is[2].size() == 1) return 0;
		if(is[2].size() == 0) {
			for(int i = 1; i < is[1].size(); i++) {
				b[is[1][i-1]][is[1][i]] = 1;
				b[is[1][i]][is[1][i-1]] = 1;
			}
		} else if(is[1].size() == 0) {
			for(int i = 1; i < is[2].size(); i++) {
				b[is[2][i-1]][is[2][i]] = 1;
				b[is[2][i]][is[2][i-1]] = 1;
			}
			b[is[2][is[2].size()-1]][is[2][0]] = 1;
			b[is[2][0]][is[2][is[2].size()-1]] = 1;
			if(is[2].size() == 2) return 0;
		} else {
			for(int i = 1; i < is[1].size(); i++) {
				b[is[1][i-1]][is[1][i]] = 1;
				b[is[1][i]][is[1][i-1]] = 1;
			}
			for(int i = 1; i < is[2].size(); i++) {
				b[is[2][i-1]][is[2][i]] = 1;
				b[is[2][i]][is[2][i-1]] = 1;
			}
			b[is[2][0]][is[1][is[1].size()-1]] = 1;
			b[is[1][is[1].size()-1]][is[2][0]] = 1;
			b[is[2][is[2].size()-1]][is[1][is[1].size()-1]] = 1;
			b[is[1][is[1].size()-1]][is[2][is[2].size()-1]] = 1;
		}
	}

	if(!possible)
		return 0;
	
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |    for(int i = 1; i < is[1].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:97:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:105:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |    for(int i = 1; i < is[1].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:109:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 267 ms 30200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 267 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 253 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 126 ms 18808 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6904 KB Output is correct
21 Correct 249 ms 26616 KB Output is correct
22 Correct 249 ms 26104 KB Output is correct
23 Correct 269 ms 28152 KB Output is correct
24 Correct 243 ms 26104 KB Output is correct
25 Correct 112 ms 16632 KB Output is correct
26 Correct 103 ms 16248 KB Output is correct
27 Correct 279 ms 29304 KB Output is correct
28 Correct 244 ms 26232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 242 ms 26360 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1664 KB Output is correct
13 Correct 265 ms 30200 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 122 ms 18800 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 62 ms 6904 KB Output is correct
22 Correct 253 ms 26616 KB Output is correct
23 Correct 244 ms 26104 KB Output is correct
24 Correct 261 ms 29180 KB Output is correct
25 Correct 115 ms 16248 KB Output is correct
26 Correct 109 ms 16632 KB Output is correct
27 Correct 244 ms 26104 KB Output is correct
28 Correct 262 ms 28152 KB Output is correct
29 Correct 105 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 62 ms 6904 KB Output is correct
5 Correct 253 ms 26744 KB Output is correct
6 Correct 242 ms 26108 KB Output is correct
7 Correct 260 ms 28148 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 62 ms 6904 KB Output is correct
10 Correct 253 ms 26616 KB Output is correct
11 Correct 246 ms 26232 KB Output is correct
12 Correct 257 ms 29304 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Incorrect 28 ms 4344 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 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 267 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 253 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 126 ms 18808 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6904 KB Output is correct
21 Correct 249 ms 26616 KB Output is correct
22 Correct 249 ms 26104 KB Output is correct
23 Correct 269 ms 28152 KB Output is correct
24 Correct 243 ms 26104 KB Output is correct
25 Correct 112 ms 16632 KB Output is correct
26 Correct 103 ms 16248 KB Output is correct
27 Correct 279 ms 29304 KB Output is correct
28 Correct 244 ms 26232 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 242 ms 26360 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 265 ms 30200 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1280 KB Output is correct
45 Correct 122 ms 18800 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 6904 KB Output is correct
50 Correct 253 ms 26616 KB Output is correct
51 Correct 244 ms 26104 KB Output is correct
52 Correct 261 ms 29180 KB Output is correct
53 Correct 115 ms 16248 KB Output is correct
54 Correct 109 ms 16632 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 262 ms 28152 KB Output is correct
57 Correct 105 ms 16248 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 1152 KB Output is correct
61 Correct 129 ms 20216 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Incorrect 28 ms 4352 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 267 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 253 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 126 ms 18808 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6904 KB Output is correct
21 Correct 249 ms 26616 KB Output is correct
22 Correct 249 ms 26104 KB Output is correct
23 Correct 269 ms 28152 KB Output is correct
24 Correct 243 ms 26104 KB Output is correct
25 Correct 112 ms 16632 KB Output is correct
26 Correct 103 ms 16248 KB Output is correct
27 Correct 279 ms 29304 KB Output is correct
28 Correct 244 ms 26232 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 242 ms 26360 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 265 ms 30200 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1280 KB Output is correct
45 Correct 122 ms 18800 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 6904 KB Output is correct
50 Correct 253 ms 26616 KB Output is correct
51 Correct 244 ms 26104 KB Output is correct
52 Correct 261 ms 29180 KB Output is correct
53 Correct 115 ms 16248 KB Output is correct
54 Correct 109 ms 16632 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 262 ms 28152 KB Output is correct
57 Correct 105 ms 16248 KB Output is correct
58 Correct 1 ms 512 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 62 ms 6904 KB Output is correct
62 Correct 253 ms 26744 KB Output is correct
63 Correct 242 ms 26108 KB Output is correct
64 Correct 260 ms 28148 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 62 ms 6904 KB Output is correct
67 Correct 253 ms 26616 KB Output is correct
68 Correct 246 ms 26232 KB Output is correct
69 Correct 257 ms 29304 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Incorrect 28 ms 4344 KB Answer gives possible 0 while actual possible 1
74 Halted 0 ms 0 KB -