Submission #404738

# Submission time Handle Problem Language Result Execution time Memory
404738 2021-05-14T22:26:02 Z monus1042 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
281 ms 28124 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
 
const int NAX = 1002;
vector<int> parent(NAX, -1), parent2(NAX, -1);
vector<vector<int> > answer;
 
vector<vector<int> > P(NAX, vector<int>(NAX));
vector<vector<int> > gsetone(NAX), adj(NAX);

bool vis[NAX];
 
int n;
 
int Find(int u){
	if (parent[u] == -1) return u;
	return parent[u] = Find(parent[u]);
}
 
int Find2(int u){
	if (parent2[u] == -1) return u;
	return parent2[u] = Find2(parent2[u]);
}
 
int construct(vector<vector<int> > p) {
	n = p.size();
	for (int i=0; i<n; i++){
		vector<int> row(n);
		answer.push_back(row);
	}
	
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			P[i][j] = p[i][j];
			if (P[i][j] == 3) return 0;
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (i==j) continue;
			if (P[i][j] == 1){ // first do the bamboos
				int x = Find(i), y = Find(j);
				if (x != y){
					parent[x] = y;
				}
			}
		}
	}
	for (int i=0; i<n; i++){
		int pp = Find(i);
		if (pp != i) gsetone[pp].push_back(i);
	}
	for (int i=0; i<n; i++){
		int u = i;
		for (int j=0; j<gsetone[i].size(); j++){
			int v = gsetone[i][j];
			answer[u][v] = answer[v][u] = 1;
			u = v;
		}
	}
	// do the twos
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (i==j) continue;
			if (P[i][j] == 2){
				int x = Find(i), y = Find(j);
				int X = Find2(x), Y = Find2(y);
				if (X != Y){
					parent2[X] = Y;
				}
			}
		}
	}
	for (int i=0; i<n; i++){
		int pp = Find(i);
		int PP = Find2(pp);
		if (PP != pp && !vis[pp]){
			adj[PP].push_back(pp);
			vis[pp] = true;
		}
	}
	for (int i=0; i<n; i++){
		if ((int)adj[i].size() == 1) return 0;
		int u = i;
		for (int j=0; j<adj[i].size(); j++){
			int v = adj[i][j];
			answer[u][v] = answer[v][u] = 1;
			u = v;
		}
		if ((int)adj[i].size() > 1) answer[u][i] = answer[i][u] = 1;
	}
	// check everything:
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (i==j) continue;
			int x = Find(i), y = Find(j);
			int X = Find2(x), Y = Find2(y);
			if (P[i][j] == 0){
				if (X == Y) return 0;
			}else if (P[i][j] == 1){
				if (x != y) return 0;
			}else{
				if (x == y || X != Y) return 0;
			}
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int j=0; j<gsetone[i].size(); j++){
      |                 ~^~~~~~~~~~~~~~~~~~
supertrees.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   for (int j=0; j<adj[i].size(); j++){
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4300 KB Output is correct
5 Correct 3 ms 4300 KB Output is correct
6 Correct 13 ms 5192 KB Output is correct
7 Correct 247 ms 27952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4300 KB Output is correct
5 Correct 3 ms 4300 KB Output is correct
6 Correct 13 ms 5192 KB Output is correct
7 Correct 247 ms 27952 KB Output is correct
8 Correct 3 ms 4300 KB Output is correct
9 Correct 3 ms 4300 KB Output is correct
10 Correct 3 ms 4292 KB Output is correct
11 Correct 3 ms 4300 KB Output is correct
12 Correct 13 ms 5212 KB Output is correct
13 Correct 239 ms 27936 KB Output is correct
14 Correct 3 ms 4300 KB Output is correct
15 Correct 3 ms 4300 KB Output is correct
16 Correct 10 ms 4828 KB Output is correct
17 Correct 128 ms 18088 KB Output is correct
18 Correct 3 ms 4300 KB Output is correct
19 Correct 3 ms 4300 KB Output is correct
20 Correct 64 ms 10264 KB Output is correct
21 Correct 243 ms 27940 KB Output is correct
22 Correct 257 ms 27944 KB Output is correct
23 Correct 270 ms 27952 KB Output is correct
24 Correct 246 ms 27936 KB Output is correct
25 Correct 103 ms 18020 KB Output is correct
26 Correct 100 ms 18080 KB Output is correct
27 Correct 270 ms 27936 KB Output is correct
28 Correct 236 ms 27948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4248 KB Output is correct
5 Correct 3 ms 4312 KB Output is correct
6 Correct 4 ms 4300 KB Output is correct
7 Correct 4 ms 4300 KB Output is correct
8 Correct 13 ms 5224 KB Output is correct
9 Correct 237 ms 28008 KB Output is correct
10 Correct 3 ms 4300 KB Output is correct
11 Correct 3 ms 4320 KB Output is correct
12 Correct 13 ms 5224 KB Output is correct
13 Correct 258 ms 27972 KB Output is correct
14 Correct 3 ms 4300 KB Output is correct
15 Correct 3 ms 4300 KB Output is correct
16 Correct 8 ms 4812 KB Output is correct
17 Correct 148 ms 18084 KB Output is correct
18 Correct 3 ms 4300 KB Output is correct
19 Correct 3 ms 4320 KB Output is correct
20 Correct 3 ms 4300 KB Output is correct
21 Correct 63 ms 10180 KB Output is correct
22 Correct 244 ms 28008 KB Output is correct
23 Correct 243 ms 27972 KB Output is correct
24 Correct 265 ms 27940 KB Output is correct
25 Correct 98 ms 18096 KB Output is correct
26 Correct 111 ms 18084 KB Output is correct
27 Correct 239 ms 27948 KB Output is correct
28 Correct 263 ms 27968 KB Output is correct
29 Correct 98 ms 18116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 62 ms 10272 KB Output is correct
5 Correct 242 ms 27976 KB Output is correct
6 Correct 258 ms 27936 KB Output is correct
7 Correct 279 ms 27936 KB Output is correct
8 Correct 3 ms 4300 KB Output is correct
9 Correct 62 ms 10204 KB Output is correct
10 Correct 249 ms 27932 KB Output is correct
11 Correct 238 ms 27948 KB Output is correct
12 Correct 281 ms 28124 KB Output is correct
13 Correct 4 ms 4300 KB Output is correct
14 Correct 3 ms 4300 KB Output is correct
15 Correct 3 ms 4300 KB Output is correct
16 Correct 65 ms 10252 KB Output is correct
17 Correct 251 ms 27928 KB Output is correct
18 Correct 249 ms 28080 KB Output is correct
19 Correct 262 ms 27916 KB Output is correct
20 Correct 236 ms 27956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4300 KB Output is correct
5 Correct 3 ms 4300 KB Output is correct
6 Correct 13 ms 5192 KB Output is correct
7 Correct 247 ms 27952 KB Output is correct
8 Correct 3 ms 4300 KB Output is correct
9 Correct 3 ms 4300 KB Output is correct
10 Correct 3 ms 4292 KB Output is correct
11 Correct 3 ms 4300 KB Output is correct
12 Correct 13 ms 5212 KB Output is correct
13 Correct 239 ms 27936 KB Output is correct
14 Correct 3 ms 4300 KB Output is correct
15 Correct 3 ms 4300 KB Output is correct
16 Correct 10 ms 4828 KB Output is correct
17 Correct 128 ms 18088 KB Output is correct
18 Correct 3 ms 4300 KB Output is correct
19 Correct 3 ms 4300 KB Output is correct
20 Correct 64 ms 10264 KB Output is correct
21 Correct 243 ms 27940 KB Output is correct
22 Correct 257 ms 27944 KB Output is correct
23 Correct 270 ms 27952 KB Output is correct
24 Correct 246 ms 27936 KB Output is correct
25 Correct 103 ms 18020 KB Output is correct
26 Correct 100 ms 18080 KB Output is correct
27 Correct 270 ms 27936 KB Output is correct
28 Correct 236 ms 27948 KB Output is correct
29 Correct 3 ms 4300 KB Output is correct
30 Correct 3 ms 4300 KB Output is correct
31 Correct 3 ms 4300 KB Output is correct
32 Correct 3 ms 4248 KB Output is correct
33 Correct 3 ms 4312 KB Output is correct
34 Correct 4 ms 4300 KB Output is correct
35 Correct 4 ms 4300 KB Output is correct
36 Correct 13 ms 5224 KB Output is correct
37 Correct 237 ms 28008 KB Output is correct
38 Correct 3 ms 4300 KB Output is correct
39 Correct 3 ms 4320 KB Output is correct
40 Correct 13 ms 5224 KB Output is correct
41 Correct 258 ms 27972 KB Output is correct
42 Correct 3 ms 4300 KB Output is correct
43 Correct 3 ms 4300 KB Output is correct
44 Correct 8 ms 4812 KB Output is correct
45 Correct 148 ms 18084 KB Output is correct
46 Correct 3 ms 4300 KB Output is correct
47 Correct 3 ms 4320 KB Output is correct
48 Correct 3 ms 4300 KB Output is correct
49 Correct 63 ms 10180 KB Output is correct
50 Correct 244 ms 28008 KB Output is correct
51 Correct 243 ms 27972 KB Output is correct
52 Correct 265 ms 27940 KB Output is correct
53 Correct 98 ms 18096 KB Output is correct
54 Correct 111 ms 18084 KB Output is correct
55 Correct 239 ms 27948 KB Output is correct
56 Correct 263 ms 27968 KB Output is correct
57 Correct 98 ms 18116 KB Output is correct
58 Correct 3 ms 4300 KB Output is correct
59 Correct 3 ms 4300 KB Output is correct
60 Correct 8 ms 4812 KB Output is correct
61 Correct 126 ms 18116 KB Output is correct
62 Correct 3 ms 4300 KB Output is correct
63 Correct 3 ms 4300 KB Output is correct
64 Correct 3 ms 4300 KB Output is correct
65 Correct 78 ms 10180 KB Output is correct
66 Correct 105 ms 18092 KB Output is correct
67 Correct 104 ms 18108 KB Output is correct
68 Correct 104 ms 18088 KB Output is correct
69 Correct 99 ms 18100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4300 KB Output is correct
5 Correct 3 ms 4300 KB Output is correct
6 Correct 13 ms 5192 KB Output is correct
7 Correct 247 ms 27952 KB Output is correct
8 Correct 3 ms 4300 KB Output is correct
9 Correct 3 ms 4300 KB Output is correct
10 Correct 3 ms 4292 KB Output is correct
11 Correct 3 ms 4300 KB Output is correct
12 Correct 13 ms 5212 KB Output is correct
13 Correct 239 ms 27936 KB Output is correct
14 Correct 3 ms 4300 KB Output is correct
15 Correct 3 ms 4300 KB Output is correct
16 Correct 10 ms 4828 KB Output is correct
17 Correct 128 ms 18088 KB Output is correct
18 Correct 3 ms 4300 KB Output is correct
19 Correct 3 ms 4300 KB Output is correct
20 Correct 64 ms 10264 KB Output is correct
21 Correct 243 ms 27940 KB Output is correct
22 Correct 257 ms 27944 KB Output is correct
23 Correct 270 ms 27952 KB Output is correct
24 Correct 246 ms 27936 KB Output is correct
25 Correct 103 ms 18020 KB Output is correct
26 Correct 100 ms 18080 KB Output is correct
27 Correct 270 ms 27936 KB Output is correct
28 Correct 236 ms 27948 KB Output is correct
29 Correct 3 ms 4300 KB Output is correct
30 Correct 3 ms 4300 KB Output is correct
31 Correct 3 ms 4300 KB Output is correct
32 Correct 3 ms 4248 KB Output is correct
33 Correct 3 ms 4312 KB Output is correct
34 Correct 4 ms 4300 KB Output is correct
35 Correct 4 ms 4300 KB Output is correct
36 Correct 13 ms 5224 KB Output is correct
37 Correct 237 ms 28008 KB Output is correct
38 Correct 3 ms 4300 KB Output is correct
39 Correct 3 ms 4320 KB Output is correct
40 Correct 13 ms 5224 KB Output is correct
41 Correct 258 ms 27972 KB Output is correct
42 Correct 3 ms 4300 KB Output is correct
43 Correct 3 ms 4300 KB Output is correct
44 Correct 8 ms 4812 KB Output is correct
45 Correct 148 ms 18084 KB Output is correct
46 Correct 3 ms 4300 KB Output is correct
47 Correct 3 ms 4320 KB Output is correct
48 Correct 3 ms 4300 KB Output is correct
49 Correct 63 ms 10180 KB Output is correct
50 Correct 244 ms 28008 KB Output is correct
51 Correct 243 ms 27972 KB Output is correct
52 Correct 265 ms 27940 KB Output is correct
53 Correct 98 ms 18096 KB Output is correct
54 Correct 111 ms 18084 KB Output is correct
55 Correct 239 ms 27948 KB Output is correct
56 Correct 263 ms 27968 KB Output is correct
57 Correct 98 ms 18116 KB Output is correct
58 Correct 3 ms 4300 KB Output is correct
59 Correct 3 ms 4300 KB Output is correct
60 Correct 3 ms 4300 KB Output is correct
61 Correct 62 ms 10272 KB Output is correct
62 Correct 242 ms 27976 KB Output is correct
63 Correct 258 ms 27936 KB Output is correct
64 Correct 279 ms 27936 KB Output is correct
65 Correct 3 ms 4300 KB Output is correct
66 Correct 62 ms 10204 KB Output is correct
67 Correct 249 ms 27932 KB Output is correct
68 Correct 238 ms 27948 KB Output is correct
69 Correct 281 ms 28124 KB Output is correct
70 Correct 4 ms 4300 KB Output is correct
71 Correct 3 ms 4300 KB Output is correct
72 Correct 3 ms 4300 KB Output is correct
73 Correct 65 ms 10252 KB Output is correct
74 Correct 251 ms 27928 KB Output is correct
75 Correct 249 ms 28080 KB Output is correct
76 Correct 262 ms 27916 KB Output is correct
77 Correct 236 ms 27956 KB Output is correct
78 Correct 3 ms 4300 KB Output is correct
79 Correct 3 ms 4300 KB Output is correct
80 Correct 8 ms 4812 KB Output is correct
81 Correct 126 ms 18116 KB Output is correct
82 Correct 3 ms 4300 KB Output is correct
83 Correct 3 ms 4300 KB Output is correct
84 Correct 3 ms 4300 KB Output is correct
85 Correct 78 ms 10180 KB Output is correct
86 Correct 105 ms 18092 KB Output is correct
87 Correct 104 ms 18108 KB Output is correct
88 Correct 104 ms 18088 KB Output is correct
89 Correct 99 ms 18100 KB Output is correct
90 Correct 3 ms 4300 KB Output is correct
91 Correct 3 ms 4300 KB Output is correct
92 Correct 7 ms 4804 KB Output is correct
93 Correct 103 ms 18088 KB Output is correct
94 Correct 3 ms 4300 KB Output is correct
95 Correct 3 ms 4300 KB Output is correct
96 Correct 3 ms 4300 KB Output is correct
97 Correct 28 ms 7748 KB Output is correct
98 Correct 99 ms 18084 KB Output is correct
99 Correct 100 ms 18084 KB Output is correct
100 Correct 100 ms 17988 KB Output is correct
101 Correct 96 ms 18088 KB Output is correct
102 Correct 109 ms 18096 KB Output is correct
103 Correct 96 ms 18116 KB Output is correct
104 Correct 96 ms 18080 KB Output is correct
105 Correct 106 ms 18088 KB Output is correct