// :)
#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);
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;
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;
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:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++)
| ~~^~~~~~~~~~~~
supertrees.cpp:54:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++)
| ~~^~~~~~~~~~~~
supertrees.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
| ~~^~~~~~~~~~~
supertrees.cpp:60:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2008 KB |
Output is correct |
7 |
Correct |
159 ms |
26000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2008 KB |
Output is correct |
7 |
Correct |
159 ms |
26000 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 |
1972 KB |
Output is correct |
13 |
Correct |
175 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
75 ms |
16136 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
7744 KB |
Output is correct |
21 |
Correct |
163 ms |
25996 KB |
Output is correct |
22 |
Correct |
158 ms |
26000 KB |
Output is correct |
23 |
Correct |
157 ms |
25932 KB |
Output is correct |
24 |
Correct |
159 ms |
25972 KB |
Output is correct |
25 |
Correct |
77 ms |
16012 KB |
Output is correct |
26 |
Correct |
65 ms |
16060 KB |
Output is correct |
27 |
Correct |
195 ms |
26008 KB |
Output is correct |
28 |
Correct |
152 ms |
25960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1972 KB |
Output is correct |
9 |
Correct |
158 ms |
25996 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 |
1956 KB |
Output is correct |
13 |
Correct |
149 ms |
25992 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
77 ms |
16152 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
46 ms |
7692 KB |
Output is correct |
22 |
Correct |
194 ms |
25924 KB |
Output is correct |
23 |
Correct |
153 ms |
25936 KB |
Output is correct |
24 |
Correct |
180 ms |
25932 KB |
Output is correct |
25 |
Correct |
67 ms |
16012 KB |
Output is correct |
26 |
Correct |
61 ms |
16020 KB |
Output is correct |
27 |
Correct |
151 ms |
25912 KB |
Output is correct |
28 |
Correct |
172 ms |
25912 KB |
Output is correct |
29 |
Correct |
66 ms |
15996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
39 ms |
7688 KB |
Output is correct |
5 |
Correct |
155 ms |
25944 KB |
Output is correct |
6 |
Correct |
159 ms |
26008 KB |
Output is correct |
7 |
Correct |
167 ms |
25968 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
51 ms |
7688 KB |
Output is correct |
10 |
Correct |
159 ms |
25996 KB |
Output is correct |
11 |
Correct |
159 ms |
26008 KB |
Output is correct |
12 |
Correct |
178 ms |
25996 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 |
40 ms |
7672 KB |
Output is correct |
17 |
Correct |
166 ms |
26008 KB |
Output is correct |
18 |
Correct |
158 ms |
25944 KB |
Output is correct |
19 |
Correct |
153 ms |
25908 KB |
Output is correct |
20 |
Correct |
176 ms |
25912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2008 KB |
Output is correct |
7 |
Correct |
159 ms |
26000 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 |
1972 KB |
Output is correct |
13 |
Correct |
175 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
75 ms |
16136 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
7744 KB |
Output is correct |
21 |
Correct |
163 ms |
25996 KB |
Output is correct |
22 |
Correct |
158 ms |
26000 KB |
Output is correct |
23 |
Correct |
157 ms |
25932 KB |
Output is correct |
24 |
Correct |
159 ms |
25972 KB |
Output is correct |
25 |
Correct |
77 ms |
16012 KB |
Output is correct |
26 |
Correct |
65 ms |
16060 KB |
Output is correct |
27 |
Correct |
195 ms |
26008 KB |
Output is correct |
28 |
Correct |
152 ms |
25960 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1972 KB |
Output is correct |
37 |
Correct |
158 ms |
25996 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 |
1956 KB |
Output is correct |
41 |
Correct |
149 ms |
25992 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1492 KB |
Output is correct |
45 |
Correct |
77 ms |
16152 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
46 ms |
7692 KB |
Output is correct |
50 |
Correct |
194 ms |
25924 KB |
Output is correct |
51 |
Correct |
153 ms |
25936 KB |
Output is correct |
52 |
Correct |
180 ms |
25932 KB |
Output is correct |
53 |
Correct |
67 ms |
16012 KB |
Output is correct |
54 |
Correct |
61 ms |
16020 KB |
Output is correct |
55 |
Correct |
151 ms |
25912 KB |
Output is correct |
56 |
Correct |
172 ms |
25912 KB |
Output is correct |
57 |
Correct |
66 ms |
15996 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 |
71 ms |
16136 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
39 ms |
7756 KB |
Output is correct |
66 |
Correct |
67 ms |
16012 KB |
Output is correct |
67 |
Correct |
68 ms |
16076 KB |
Output is correct |
68 |
Correct |
65 ms |
16012 KB |
Output is correct |
69 |
Correct |
65 ms |
16076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2008 KB |
Output is correct |
7 |
Correct |
159 ms |
26000 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 |
1972 KB |
Output is correct |
13 |
Correct |
175 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
75 ms |
16136 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
7744 KB |
Output is correct |
21 |
Correct |
163 ms |
25996 KB |
Output is correct |
22 |
Correct |
158 ms |
26000 KB |
Output is correct |
23 |
Correct |
157 ms |
25932 KB |
Output is correct |
24 |
Correct |
159 ms |
25972 KB |
Output is correct |
25 |
Correct |
77 ms |
16012 KB |
Output is correct |
26 |
Correct |
65 ms |
16060 KB |
Output is correct |
27 |
Correct |
195 ms |
26008 KB |
Output is correct |
28 |
Correct |
152 ms |
25960 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1972 KB |
Output is correct |
37 |
Correct |
158 ms |
25996 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 |
1956 KB |
Output is correct |
41 |
Correct |
149 ms |
25992 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1492 KB |
Output is correct |
45 |
Correct |
77 ms |
16152 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
46 ms |
7692 KB |
Output is correct |
50 |
Correct |
194 ms |
25924 KB |
Output is correct |
51 |
Correct |
153 ms |
25936 KB |
Output is correct |
52 |
Correct |
180 ms |
25932 KB |
Output is correct |
53 |
Correct |
67 ms |
16012 KB |
Output is correct |
54 |
Correct |
61 ms |
16020 KB |
Output is correct |
55 |
Correct |
151 ms |
25912 KB |
Output is correct |
56 |
Correct |
172 ms |
25912 KB |
Output is correct |
57 |
Correct |
66 ms |
15996 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 |
39 ms |
7688 KB |
Output is correct |
62 |
Correct |
155 ms |
25944 KB |
Output is correct |
63 |
Correct |
159 ms |
26008 KB |
Output is correct |
64 |
Correct |
167 ms |
25968 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
51 ms |
7688 KB |
Output is correct |
67 |
Correct |
159 ms |
25996 KB |
Output is correct |
68 |
Correct |
159 ms |
26008 KB |
Output is correct |
69 |
Correct |
178 ms |
25996 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 |
40 ms |
7672 KB |
Output is correct |
74 |
Correct |
166 ms |
26008 KB |
Output is correct |
75 |
Correct |
158 ms |
25944 KB |
Output is correct |
76 |
Correct |
153 ms |
25908 KB |
Output is correct |
77 |
Correct |
176 ms |
25912 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 |
71 ms |
16136 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
39 ms |
7756 KB |
Output is correct |
86 |
Correct |
67 ms |
16012 KB |
Output is correct |
87 |
Correct |
68 ms |
16076 KB |
Output is correct |
88 |
Correct |
65 ms |
16012 KB |
Output is correct |
89 |
Correct |
65 ms |
16076 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 |
69 ms |
16136 KB |
Output is correct |
94 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |