Submission #300290

# Submission time Handle Problem Language Result Execution time Memory
300290 2020-09-17T04:24:10 Z aljasdlas Connecting Supertrees (IOI20_supertrees) C++14
96 / 100
270 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(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:97:24: 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 = 0; i+1 < w.size(); i++) {
      |                    ~~~~^~~~~~~~~~
supertrees.cpp:114:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 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 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 270 ms 26080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 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 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 270 ms 26080 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 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 241 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 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 72 ms 6776 KB Output is correct
21 Correct 250 ms 26104 KB Output is correct
22 Correct 246 ms 26208 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 264 ms 26060 KB Output is correct
25 Correct 115 ms 16120 KB Output is correct
26 Correct 117 ms 16120 KB Output is correct
27 Correct 257 ms 26104 KB Output is correct
28 Correct 252 ms 26232 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 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 1408 KB Output is correct
9 Correct 239 ms 26108 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 251 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 119 ms 16248 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 61 ms 6776 KB Output is correct
22 Correct 252 ms 26088 KB Output is correct
23 Correct 245 ms 26360 KB Output is correct
24 Correct 251 ms 26248 KB Output is correct
25 Correct 110 ms 16120 KB Output is correct
26 Correct 110 ms 16120 KB Output is correct
27 Correct 247 ms 26104 KB Output is correct
28 Correct 253 ms 26144 KB Output is correct
29 Correct 121 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 63 ms 6776 KB Output is correct
5 Correct 251 ms 26104 KB Output is correct
6 Correct 244 ms 26104 KB Output is correct
7 Correct 255 ms 26232 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 63 ms 6776 KB Output is correct
10 Correct 249 ms 26104 KB Output is correct
11 Correct 251 ms 26104 KB Output is correct
12 Correct 251 ms 26232 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 64 ms 6780 KB Output is correct
17 Correct 246 ms 26232 KB Output is correct
18 Correct 251 ms 26104 KB Output is correct
19 Correct 245 ms 26108 KB Output is correct
20 Correct 248 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 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 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 270 ms 26080 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 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 241 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 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 72 ms 6776 KB Output is correct
21 Correct 250 ms 26104 KB Output is correct
22 Correct 246 ms 26208 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 264 ms 26060 KB Output is correct
25 Correct 115 ms 16120 KB Output is correct
26 Correct 117 ms 16120 KB Output is correct
27 Correct 257 ms 26104 KB Output is correct
28 Correct 252 ms 26232 KB Output is correct
29 Correct 1 ms 256 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 256 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1408 KB Output is correct
37 Correct 239 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 251 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 119 ms 16248 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 6776 KB Output is correct
50 Correct 252 ms 26088 KB Output is correct
51 Correct 245 ms 26360 KB Output is correct
52 Correct 251 ms 26248 KB Output is correct
53 Correct 110 ms 16120 KB Output is correct
54 Correct 110 ms 16120 KB Output is correct
55 Correct 247 ms 26104 KB Output is correct
56 Correct 253 ms 26144 KB Output is correct
57 Correct 121 ms 16120 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 5 ms 1152 KB Output is correct
61 Correct 119 ms 16352 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 62 ms 6776 KB Output is correct
66 Correct 109 ms 16120 KB Output is correct
67 Correct 109 ms 16120 KB Output is correct
68 Correct 109 ms 16120 KB Output is correct
69 Correct 109 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 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 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 270 ms 26080 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 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 241 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 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 72 ms 6776 KB Output is correct
21 Correct 250 ms 26104 KB Output is correct
22 Correct 246 ms 26208 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 264 ms 26060 KB Output is correct
25 Correct 115 ms 16120 KB Output is correct
26 Correct 117 ms 16120 KB Output is correct
27 Correct 257 ms 26104 KB Output is correct
28 Correct 252 ms 26232 KB Output is correct
29 Correct 1 ms 256 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 256 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1408 KB Output is correct
37 Correct 239 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 251 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 119 ms 16248 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 6776 KB Output is correct
50 Correct 252 ms 26088 KB Output is correct
51 Correct 245 ms 26360 KB Output is correct
52 Correct 251 ms 26248 KB Output is correct
53 Correct 110 ms 16120 KB Output is correct
54 Correct 110 ms 16120 KB Output is correct
55 Correct 247 ms 26104 KB Output is correct
56 Correct 253 ms 26144 KB Output is correct
57 Correct 121 ms 16120 KB Output is correct
58 Correct 1 ms 416 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 63 ms 6776 KB Output is correct
62 Correct 251 ms 26104 KB Output is correct
63 Correct 244 ms 26104 KB Output is correct
64 Correct 255 ms 26232 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 63 ms 6776 KB Output is correct
67 Correct 249 ms 26104 KB Output is correct
68 Correct 251 ms 26104 KB Output is correct
69 Correct 251 ms 26232 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 1 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 64 ms 6780 KB Output is correct
74 Correct 246 ms 26232 KB Output is correct
75 Correct 251 ms 26104 KB Output is correct
76 Correct 245 ms 26108 KB Output is correct
77 Correct 248 ms 26104 KB Output is correct
78 Correct 1 ms 256 KB Output is correct
79 Correct 1 ms 256 KB Output is correct
80 Correct 5 ms 1152 KB Output is correct
81 Correct 119 ms 16352 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 62 ms 6776 KB Output is correct
86 Correct 109 ms 16120 KB Output is correct
87 Correct 109 ms 16120 KB Output is correct
88 Correct 109 ms 16120 KB Output is correct
89 Correct 109 ms 16248 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 6 ms 1024 KB Output is correct
93 Correct 113 ms 16120 KB Output is correct
94 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -