Submission #300293

# Submission time Handle Problem Language Result Execution time Memory
300293 2020-09-17T04:30:33 Z aljasdlas Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
254 ms 26360 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> onevis;
bitset<1005> isOne;

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

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



void onedfs(int u) {
	onevis[u] = 1;
	onecompNum[u] = onecomponents.size();
	onecomponents.back().push_back(u);
	for(int v = 0; v < n; v++)
		if(!onevis[v] && p[u][v] == 1)
			onedfs(v);
}


int construct(vector<vector<int>> p_) {
	p = p_;
	n = p.size();

	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++) {
		if(!onevis[i]) {
			onecomponents.push_back(vector<int>(0));
		// << "Comp " << components.size() << ": ";
			onedfs(i);
		// << endl;
			if(onecomponents.back().size() == 1) {
				onecompNum[i] = 0;
				onecomponents.pop_back();
			}
		}
	}


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

	for(auto &v: components) {
		isOne.reset();
		if(v.size() == 1)
			continue;


		vector<int> is[3];
		for(auto &x: v)
			if(onecompNum[x] == 0) is[2].push_back(x);

		for(auto &x: v) {
			if(onecompNum[x] > 0) {
				auto &w = onecomponents[onecompNum[x]-1];
				for(int i = 0; i+1 < w.size(); i++) {
					b[w[i]][w[i+1]] = 1;
					b[w[i+1]][w[i]] = 1;
				}
				is[2].push_back(w.back());
				for(auto y: w)
					onecompNum[y] = -1;
			}
		}
		
		
	// << "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() == 2) return 0;

		if(is[2].size() > 2) {
			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(!possible)
		return 0;
	
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:98:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(int i = 0; i+1 < w.size(); i++) {
      |                    ~~~~^~~~~~~~~~
supertrees.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 238 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 238 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 244 ms 26104 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 106 ms 16120 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 26232 KB Output is correct
22 Correct 242 ms 26104 KB Output is correct
23 Correct 250 ms 26104 KB Output is correct
24 Correct 240 ms 26104 KB Output is correct
25 Correct 105 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 249 ms 26104 KB Output is correct
28 Correct 237 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 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 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 12 ms 1408 KB Output is correct
9 Correct 246 ms 26104 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 246 ms 26104 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 111 ms 16120 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 63 ms 6776 KB Output is correct
22 Correct 242 ms 26104 KB Output is correct
23 Correct 242 ms 26104 KB Output is correct
24 Correct 247 ms 26104 KB Output is correct
25 Correct 103 ms 16124 KB Output is correct
26 Correct 102 ms 16120 KB Output is correct
27 Correct 242 ms 26232 KB Output is correct
28 Correct 254 ms 26360 KB Output is correct
29 Correct 104 ms 16224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 68 ms 6776 KB Output is correct
5 Correct 247 ms 26104 KB Output is correct
6 Correct 245 ms 26104 KB Output is correct
7 Correct 253 ms 26084 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 63 ms 6776 KB Output is correct
10 Correct 248 ms 26232 KB Output is correct
11 Correct 246 ms 26020 KB Output is correct
12 Correct 250 ms 26104 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 64 ms 6776 KB Output is correct
17 Correct 246 ms 26104 KB Output is correct
18 Correct 247 ms 26104 KB Output is correct
19 Correct 244 ms 26104 KB Output is correct
20 Correct 239 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 238 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 244 ms 26104 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 106 ms 16120 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 26232 KB Output is correct
22 Correct 242 ms 26104 KB Output is correct
23 Correct 250 ms 26104 KB Output is correct
24 Correct 240 ms 26104 KB Output is correct
25 Correct 105 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 249 ms 26104 KB Output is correct
28 Correct 237 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 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 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 12 ms 1408 KB Output is correct
37 Correct 246 ms 26104 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 246 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 111 ms 16120 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 6776 KB Output is correct
50 Correct 242 ms 26104 KB Output is correct
51 Correct 242 ms 26104 KB Output is correct
52 Correct 247 ms 26104 KB Output is correct
53 Correct 103 ms 16124 KB Output is correct
54 Correct 102 ms 16120 KB Output is correct
55 Correct 242 ms 26232 KB Output is correct
56 Correct 254 ms 26360 KB Output is correct
57 Correct 104 ms 16224 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 5 ms 1024 KB Output is correct
61 Correct 106 ms 16220 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 68 ms 6904 KB Output is correct
66 Correct 103 ms 16120 KB Output is correct
67 Correct 103 ms 16120 KB Output is correct
68 Correct 110 ms 16248 KB Output is correct
69 Correct 107 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 238 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 244 ms 26104 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 106 ms 16120 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 26232 KB Output is correct
22 Correct 242 ms 26104 KB Output is correct
23 Correct 250 ms 26104 KB Output is correct
24 Correct 240 ms 26104 KB Output is correct
25 Correct 105 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 249 ms 26104 KB Output is correct
28 Correct 237 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 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 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 12 ms 1408 KB Output is correct
37 Correct 246 ms 26104 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 246 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 111 ms 16120 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 6776 KB Output is correct
50 Correct 242 ms 26104 KB Output is correct
51 Correct 242 ms 26104 KB Output is correct
52 Correct 247 ms 26104 KB Output is correct
53 Correct 103 ms 16124 KB Output is correct
54 Correct 102 ms 16120 KB Output is correct
55 Correct 242 ms 26232 KB Output is correct
56 Correct 254 ms 26360 KB Output is correct
57 Correct 104 ms 16224 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 288 KB Output is correct
61 Correct 68 ms 6776 KB Output is correct
62 Correct 247 ms 26104 KB Output is correct
63 Correct 245 ms 26104 KB Output is correct
64 Correct 253 ms 26084 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 63 ms 6776 KB Output is correct
67 Correct 248 ms 26232 KB Output is correct
68 Correct 246 ms 26020 KB Output is correct
69 Correct 250 ms 26104 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 64 ms 6776 KB Output is correct
74 Correct 246 ms 26104 KB Output is correct
75 Correct 247 ms 26104 KB Output is correct
76 Correct 244 ms 26104 KB Output is correct
77 Correct 239 ms 26104 KB Output is correct
78 Correct 1 ms 256 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 5 ms 1024 KB Output is correct
81 Correct 106 ms 16220 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 68 ms 6904 KB Output is correct
86 Correct 103 ms 16120 KB Output is correct
87 Correct 103 ms 16120 KB Output is correct
88 Correct 110 ms 16248 KB Output is correct
89 Correct 107 ms 16220 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 1024 KB Output is correct
93 Correct 105 ms 16248 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 256 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 28 ms 4376 KB Output is correct
98 Correct 106 ms 16120 KB Output is correct
99 Correct 104 ms 16120 KB Output is correct
100 Correct 106 ms 16188 KB Output is correct
101 Correct 102 ms 16120 KB Output is correct
102 Correct 103 ms 16220 KB Output is correct
103 Correct 102 ms 16120 KB Output is correct
104 Correct 102 ms 16120 KB Output is correct
105 Correct 108 ms 16228 KB Output is correct