#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int construct(vector<vector<int>>p) {
int n=p[0].size();
rep(i, n) rep(j, n) if(p[i][j]==3) return 0;
vector<pair<vector<int>,int>>V;
rep(i, n) {
vector<int>a;
rep(j, n) if(p[i][j]) a.pb(1); else a.pb(0);
V.pb({a, i});
}
sort(all(V));
vector<vector<int>>spojne;
vector<int>akt1=V[0].st, akt2;
akt2.pb(V[0].nd);
for(int i=1; i<V.size(); ++i) {
if(V[i].st!=akt1) {
vector<int>jakie;
rep(j, n) if(akt1[j]) jakie.pb(j);
if(jakie!=akt2) return 0;
spojne.pb(akt2);
akt1=V[i].st;
akt2.clear();
}
akt2.pb(V[i].nd);
}
vector<int>jakie;
rep(j, n) if(akt1[j]) jakie.pb(j);
if(jakie!=akt2) return 0;
spojne.pb(akt2);
vector<vector<int>>ans;
rep(i, n) {
vector<int>a;
rep(j, n) a.pb(0);
ans.pb(a);
}
for(auto i : spojne) {
V.clear();
akt1.clear();
akt2.clear();
for(auto j : i) {
vector<int>a;
rep(l, n) a.pb(p[j][l]);
V.pb({a, j});
}
sort(all(V));
vector<vector<int>>drzewa;
akt1=V[0].st;
akt2.pb(V[0].nd);
for(int j=1; j<V.size(); ++j) {
if(V[j].st!=akt1) {
jakie.clear();
rep(l, n) if(akt1[l]==1) jakie.pb(l);
if(jakie!=akt2) return 0;
drzewa.pb(akt2);
akt1=V[j].st;
akt2.clear();
}
akt2.pb(V[j].nd);
}
jakie.clear();
rep(j, n) if(akt1[j]==1) jakie.pb(j);
if(jakie!=akt2) return 0;
drzewa.pb(akt2);
for(auto j : drzewa) {
int ile=0;
rep(l, n) if(p[j[0]][l]==1) ++ile;
if(ile!=j.size()) return 0;
rep(l, j.size()-1) {
ans[j[l]][j[l+1]]=ans[j[l+1]][j[l]]=1;
}
}
if(drzewa.size()==2) return 0;
if(drzewa.size()!=1) rep(j, drzewa.size()) {
ans[drzewa[j][0]][drzewa[(j+1)%drzewa.size()][0]]=1;
ans[drzewa[(j+1)%drzewa.size()][0]][drzewa[j][0]]=1;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=1; i<V.size(); ++i) {
| ~^~~~~~~~~
supertrees.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j=1; j<V.size(); ++j) {
| ~^~~~~~~~~
supertrees.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if(ile!=j.size()) return 0;
| ~~~^~~~~~~~~~
supertrees.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
supertrees.cpp:77:25: note: in expansion of macro 'rep'
77 | rep(l, j.size()-1) {
| ^~~
supertrees.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
supertrees.cpp:82:38: note: in expansion of macro 'rep'
82 | if(drzewa.size()!=1) rep(j, drzewa.size()) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1340 KB |
Output is correct |
7 |
Correct |
270 ms |
25964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1340 KB |
Output is correct |
7 |
Correct |
270 ms |
25964 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
247 ms |
22228 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
113 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
5828 KB |
Output is correct |
21 |
Correct |
264 ms |
22464 KB |
Output is correct |
22 |
Correct |
242 ms |
22020 KB |
Output is correct |
23 |
Correct |
275 ms |
24012 KB |
Output is correct |
24 |
Correct |
253 ms |
22084 KB |
Output is correct |
25 |
Correct |
118 ms |
12028 KB |
Output is correct |
26 |
Correct |
109 ms |
12036 KB |
Output is correct |
27 |
Correct |
281 ms |
24016 KB |
Output is correct |
28 |
Correct |
247 ms |
22132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
11 ms |
1140 KB |
Output is correct |
9 |
Correct |
240 ms |
22140 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1292 KB |
Output is correct |
13 |
Correct |
261 ms |
26020 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
112 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
62 ms |
5756 KB |
Output is correct |
22 |
Correct |
256 ms |
22404 KB |
Output is correct |
23 |
Correct |
249 ms |
22084 KB |
Output is correct |
24 |
Correct |
316 ms |
23876 KB |
Output is correct |
25 |
Correct |
118 ms |
16068 KB |
Output is correct |
26 |
Correct |
118 ms |
12204 KB |
Output is correct |
27 |
Correct |
242 ms |
22012 KB |
Output is correct |
28 |
Correct |
274 ms |
24072 KB |
Output is correct |
29 |
Correct |
117 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
67 ms |
5760 KB |
Output is correct |
5 |
Correct |
262 ms |
22416 KB |
Output is correct |
6 |
Correct |
242 ms |
22084 KB |
Output is correct |
7 |
Correct |
286 ms |
24068 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
62 ms |
5760 KB |
Output is correct |
10 |
Correct |
269 ms |
22380 KB |
Output is correct |
11 |
Correct |
243 ms |
22036 KB |
Output is correct |
12 |
Correct |
265 ms |
23988 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
62 ms |
5756 KB |
Output is correct |
17 |
Correct |
254 ms |
22404 KB |
Output is correct |
18 |
Correct |
261 ms |
22524 KB |
Output is correct |
19 |
Correct |
282 ms |
22212 KB |
Output is correct |
20 |
Correct |
248 ms |
22148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1340 KB |
Output is correct |
7 |
Correct |
270 ms |
25964 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
247 ms |
22228 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
113 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
5828 KB |
Output is correct |
21 |
Correct |
264 ms |
22464 KB |
Output is correct |
22 |
Correct |
242 ms |
22020 KB |
Output is correct |
23 |
Correct |
275 ms |
24012 KB |
Output is correct |
24 |
Correct |
253 ms |
22084 KB |
Output is correct |
25 |
Correct |
118 ms |
12028 KB |
Output is correct |
26 |
Correct |
109 ms |
12036 KB |
Output is correct |
27 |
Correct |
281 ms |
24016 KB |
Output is correct |
28 |
Correct |
247 ms |
22132 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1140 KB |
Output is correct |
37 |
Correct |
240 ms |
22140 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
11 ms |
1292 KB |
Output is correct |
41 |
Correct |
261 ms |
26020 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
112 ms |
12040 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
62 ms |
5756 KB |
Output is correct |
50 |
Correct |
256 ms |
22404 KB |
Output is correct |
51 |
Correct |
249 ms |
22084 KB |
Output is correct |
52 |
Correct |
316 ms |
23876 KB |
Output is correct |
53 |
Correct |
118 ms |
16068 KB |
Output is correct |
54 |
Correct |
118 ms |
12204 KB |
Output is correct |
55 |
Correct |
242 ms |
22012 KB |
Output is correct |
56 |
Correct |
274 ms |
24072 KB |
Output is correct |
57 |
Correct |
117 ms |
16128 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
716 KB |
Output is correct |
61 |
Correct |
127 ms |
12100 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Correct |
62 ms |
5780 KB |
Output is correct |
66 |
Correct |
125 ms |
12044 KB |
Output is correct |
67 |
Correct |
116 ms |
12036 KB |
Output is correct |
68 |
Correct |
109 ms |
12100 KB |
Output is correct |
69 |
Correct |
115 ms |
16120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1340 KB |
Output is correct |
7 |
Correct |
270 ms |
25964 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1168 KB |
Output is correct |
13 |
Correct |
247 ms |
22228 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
113 ms |
12120 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
5828 KB |
Output is correct |
21 |
Correct |
264 ms |
22464 KB |
Output is correct |
22 |
Correct |
242 ms |
22020 KB |
Output is correct |
23 |
Correct |
275 ms |
24012 KB |
Output is correct |
24 |
Correct |
253 ms |
22084 KB |
Output is correct |
25 |
Correct |
118 ms |
12028 KB |
Output is correct |
26 |
Correct |
109 ms |
12036 KB |
Output is correct |
27 |
Correct |
281 ms |
24016 KB |
Output is correct |
28 |
Correct |
247 ms |
22132 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1140 KB |
Output is correct |
37 |
Correct |
240 ms |
22140 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
11 ms |
1292 KB |
Output is correct |
41 |
Correct |
261 ms |
26020 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
112 ms |
12040 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
62 ms |
5756 KB |
Output is correct |
50 |
Correct |
256 ms |
22404 KB |
Output is correct |
51 |
Correct |
249 ms |
22084 KB |
Output is correct |
52 |
Correct |
316 ms |
23876 KB |
Output is correct |
53 |
Correct |
118 ms |
16068 KB |
Output is correct |
54 |
Correct |
118 ms |
12204 KB |
Output is correct |
55 |
Correct |
242 ms |
22012 KB |
Output is correct |
56 |
Correct |
274 ms |
24072 KB |
Output is correct |
57 |
Correct |
117 ms |
16128 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
67 ms |
5760 KB |
Output is correct |
62 |
Correct |
262 ms |
22416 KB |
Output is correct |
63 |
Correct |
242 ms |
22084 KB |
Output is correct |
64 |
Correct |
286 ms |
24068 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
62 ms |
5760 KB |
Output is correct |
67 |
Correct |
269 ms |
22380 KB |
Output is correct |
68 |
Correct |
243 ms |
22036 KB |
Output is correct |
69 |
Correct |
265 ms |
23988 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
62 ms |
5756 KB |
Output is correct |
74 |
Correct |
254 ms |
22404 KB |
Output is correct |
75 |
Correct |
261 ms |
22524 KB |
Output is correct |
76 |
Correct |
282 ms |
22212 KB |
Output is correct |
77 |
Correct |
248 ms |
22148 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
0 ms |
204 KB |
Output is correct |
80 |
Correct |
5 ms |
716 KB |
Output is correct |
81 |
Correct |
127 ms |
12100 KB |
Output is correct |
82 |
Correct |
0 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
0 ms |
204 KB |
Output is correct |
85 |
Correct |
62 ms |
5780 KB |
Output is correct |
86 |
Correct |
125 ms |
12044 KB |
Output is correct |
87 |
Correct |
116 ms |
12036 KB |
Output is correct |
88 |
Correct |
109 ms |
12100 KB |
Output is correct |
89 |
Correct |
115 ms |
16120 KB |
Output is correct |
90 |
Correct |
0 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
4 ms |
588 KB |
Output is correct |
93 |
Correct |
96 ms |
8072 KB |
Output is correct |
94 |
Correct |
0 ms |
204 KB |
Output is correct |
95 |
Correct |
0 ms |
204 KB |
Output is correct |
96 |
Correct |
0 ms |
204 KB |
Output is correct |
97 |
Correct |
23 ms |
2676 KB |
Output is correct |
98 |
Correct |
94 ms |
10108 KB |
Output is correct |
99 |
Correct |
96 ms |
10100 KB |
Output is correct |
100 |
Correct |
92 ms |
10104 KB |
Output is correct |
101 |
Correct |
93 ms |
10052 KB |
Output is correct |
102 |
Correct |
92 ms |
10104 KB |
Output is correct |
103 |
Correct |
92 ms |
10088 KB |
Output is correct |
104 |
Correct |
97 ms |
10052 KB |
Output is correct |
105 |
Correct |
103 ms |
10104 KB |
Output is correct |