Submission #823017

# Submission time Handle Problem Language Result Execution time Memory
823017 2023-08-12T07:04:28 Z fatemetmhr Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
207 ms 26028 KB
// :)

#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define fi     first
#define se     second
#define mp     make_pair
#define pb     push_back

typedef long long ll;


const int maxn5 = 1e3 + 10;

vector<vector<int>> ret;
vector <int> tp, av, ver;
bool mark[maxn5], mark2[maxn5];
int n, a[maxn5][maxn5];

void dfs0(int v){
	mark[v] = true;
	ver.pb(v);
	for(int i = 0; i < n; i++) if(a[v][i] > 0 && !mark[i])
		dfs0(i);
}

void dfs1(int v){
	mark2[v] = true;
	av.pb(v);
	for(int i = 0; i < n; i++) if(a[v][i] == 1 && !mark2[i]){
		ret[v][i] = ret[i][v] = 1;
		dfs1(i);
	}
}

int construct(std::vector<std::vector<int>> p) {
	n = p.size();
	for (int i = 0; i < n; i++){
		vector<int> row;
		row.resize(n);
		fill(all(row), 0);
		ret.push_back(row);
		for(int j = 0; j < n; j++)
			a[i][j] = p[i][j];
	}
	for(int i = 0; i < n; i++) if(!mark[i]){
		ver.clear();
		tp.clear();
		dfs0(i);
		int mx = 0, cnt2 = 0;
		for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++){
			if(a[ver[j]][ver[k]] == 0)
				return 0;
			mx = max(mx, a[ver[j]][ver[k]]);
			cnt2 += (a[ver[j]][ver[k]] == 2);
		}
		for(auto u : ver) if(!mark2[u]){
			av.clear();
			dfs1(u);
			for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
				if(a[av[i]][av[j]] != 1)
					return 0;
			tp.pb(u);
		}
		if(tp.size() == 2)
			return 0;
		if(mx == 3 && (tp.size() != 4 || cnt2 > 0))
			return 0;
		if(mx == 3){
			int a = tp[0], b = tp[1], c = tp[2], d = tp[3];
			ret[a][b] = ret[b][a] = 1;
			ret[b][c] = ret[c][b] = 1;
			ret[c][d] = ret[d][c] = 1;
			ret[d][a] = ret[a][d] = 1;
			ret[a][c] = ret[c][a] = 1;
		}
		else{
			for(int i = 1; i < int(tp.size()); i++)
				ret[tp[i]][tp[i - 1]] = ret[tp[i - 1]][tp[i]] = 1;
			if(tp.size() > 1)
				ret[tp.back()][tp[0]] = ret[tp[0]][tp.back()] = 1;
		}
	}
	build(ret);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++){
      |                  ~~^~~~~~~~~~~~
supertrees.cpp:55:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++){
      |                                                      ~~^~~~~~~~~~~~
supertrees.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
      |                   ~~^~~~~~~~~~~
supertrees.cpp:64:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
      |                                                      ~~^~~~~~~~~~~
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 7 ms 1984 KB Output is correct
7 Correct 160 ms 25992 KB Output is correct
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 7 ms 1984 KB Output is correct
7 Correct 160 ms 25992 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 26012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 86 ms 16140 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7736 KB Output is correct
21 Correct 158 ms 25996 KB Output is correct
22 Correct 158 ms 25900 KB Output is correct
23 Correct 169 ms 26000 KB Output is correct
24 Correct 160 ms 25976 KB Output is correct
25 Correct 69 ms 16012 KB Output is correct
26 Correct 66 ms 16008 KB Output is correct
27 Correct 165 ms 25996 KB Output is correct
28 Correct 186 ms 25996 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 1 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 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 10 ms 1932 KB Output is correct
9 Correct 157 ms 26012 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 2004 KB Output is correct
13 Correct 171 ms 25944 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 80 ms 16072 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 40 ms 7724 KB Output is correct
22 Correct 160 ms 25996 KB Output is correct
23 Correct 157 ms 26004 KB Output is correct
24 Correct 166 ms 25988 KB Output is correct
25 Correct 68 ms 16016 KB Output is correct
26 Correct 62 ms 16024 KB Output is correct
27 Correct 162 ms 25996 KB Output is correct
28 Correct 164 ms 25968 KB Output is correct
29 Correct 67 ms 16008 KB Output is correct
# 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 212 KB Output is correct
4 Correct 40 ms 7696 KB Output is correct
5 Correct 161 ms 26000 KB Output is correct
6 Correct 168 ms 26004 KB Output is correct
7 Correct 207 ms 26028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 46 ms 7696 KB Output is correct
10 Correct 167 ms 25936 KB Output is correct
11 Correct 159 ms 25996 KB Output is correct
12 Correct 167 ms 25932 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 41 ms 7744 KB Output is correct
17 Correct 169 ms 26008 KB Output is correct
18 Correct 177 ms 26004 KB Output is correct
19 Correct 159 ms 26008 KB Output is correct
20 Correct 157 ms 25976 KB Output is correct
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 7 ms 1984 KB Output is correct
7 Correct 160 ms 25992 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 26012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 86 ms 16140 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7736 KB Output is correct
21 Correct 158 ms 25996 KB Output is correct
22 Correct 158 ms 25900 KB Output is correct
23 Correct 169 ms 26000 KB Output is correct
24 Correct 160 ms 25976 KB Output is correct
25 Correct 69 ms 16012 KB Output is correct
26 Correct 66 ms 16008 KB Output is correct
27 Correct 165 ms 25996 KB Output is correct
28 Correct 186 ms 25996 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 10 ms 1932 KB Output is correct
37 Correct 157 ms 26012 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 2004 KB Output is correct
41 Correct 171 ms 25944 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1492 KB Output is correct
45 Correct 80 ms 16072 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 7724 KB Output is correct
50 Correct 160 ms 25996 KB Output is correct
51 Correct 157 ms 26004 KB Output is correct
52 Correct 166 ms 25988 KB Output is correct
53 Correct 68 ms 16016 KB Output is correct
54 Correct 62 ms 16024 KB Output is correct
55 Correct 162 ms 25996 KB Output is correct
56 Correct 164 ms 25968 KB Output is correct
57 Correct 67 ms 16008 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 3 ms 1492 KB Output is correct
61 Correct 74 ms 16152 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 49 ms 7680 KB Output is correct
66 Correct 73 ms 16008 KB Output is correct
67 Correct 67 ms 16012 KB Output is correct
68 Correct 65 ms 16016 KB Output is correct
69 Correct 66 ms 16024 KB Output is correct
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 7 ms 1984 KB Output is correct
7 Correct 160 ms 25992 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 26012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 86 ms 16140 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7736 KB Output is correct
21 Correct 158 ms 25996 KB Output is correct
22 Correct 158 ms 25900 KB Output is correct
23 Correct 169 ms 26000 KB Output is correct
24 Correct 160 ms 25976 KB Output is correct
25 Correct 69 ms 16012 KB Output is correct
26 Correct 66 ms 16008 KB Output is correct
27 Correct 165 ms 25996 KB Output is correct
28 Correct 186 ms 25996 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 10 ms 1932 KB Output is correct
37 Correct 157 ms 26012 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 2004 KB Output is correct
41 Correct 171 ms 25944 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1492 KB Output is correct
45 Correct 80 ms 16072 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 7724 KB Output is correct
50 Correct 160 ms 25996 KB Output is correct
51 Correct 157 ms 26004 KB Output is correct
52 Correct 166 ms 25988 KB Output is correct
53 Correct 68 ms 16016 KB Output is correct
54 Correct 62 ms 16024 KB Output is correct
55 Correct 162 ms 25996 KB Output is correct
56 Correct 164 ms 25968 KB Output is correct
57 Correct 67 ms 16008 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 40 ms 7696 KB Output is correct
62 Correct 161 ms 26000 KB Output is correct
63 Correct 168 ms 26004 KB Output is correct
64 Correct 207 ms 26028 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 46 ms 7696 KB Output is correct
67 Correct 167 ms 25936 KB Output is correct
68 Correct 159 ms 25996 KB Output is correct
69 Correct 167 ms 25932 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 41 ms 7744 KB Output is correct
74 Correct 169 ms 26008 KB Output is correct
75 Correct 177 ms 26004 KB Output is correct
76 Correct 159 ms 26008 KB Output is correct
77 Correct 157 ms 25976 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 3 ms 1492 KB Output is correct
81 Correct 74 ms 16152 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 49 ms 7680 KB Output is correct
86 Correct 73 ms 16008 KB Output is correct
87 Correct 67 ms 16012 KB Output is correct
88 Correct 65 ms 16016 KB Output is correct
89 Correct 66 ms 16024 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 3 ms 1492 KB Output is correct
93 Correct 79 ms 16136 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 24 ms 5272 KB Output is correct
98 Correct 80 ms 16016 KB Output is correct
99 Correct 72 ms 16008 KB Output is correct
100 Correct 69 ms 16076 KB Output is correct
101 Correct 68 ms 16012 KB Output is correct
102 Correct 74 ms 16136 KB Output is correct
103 Correct 70 ms 16076 KB Output is correct
104 Correct 75 ms 16148 KB Output is correct
105 Correct 77 ms 16276 KB Output is correct