#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
#define double long double
#define ull unsigned long long
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define s second
#define f first
#define pb push_back
#define oo 1000000000000000000ll
int solve_cmp(vector<int>& cmp, vector<vector<int>>& p, vector<vector<int>>& ans){
vector<vector<int>> tree;
vector<int> tree_n(cmp.size(), -1);
for (int i = 0; i < cmp.size(); ++i) {
for (int j = 0; j < i; ++j) {
if (p[cmp[i]][cmp[j]] == 1){
if (tree_n[i] != -1 && tree_n[i] != tree_n[j]) return 0;
if (tree_n[i] != -1) continue;
tree_n[i] = tree_n[j];
tree[tree_n[i]].pb(i);
}
}
if (tree_n[i] == -1) tree_n[i] = tree.size(), tree.pb({i});
}
if (tree.size() == 2) return 0;
vector<int> rt;
for (auto v : tree){
vector<bool> cur(cmp.size());
for (int i = 0; i < v.size(); ++i) {
cur[v[i]] = true;
}
for (int i = 0; i < v.size(); ++i) {
for (int j = 0; j < cmp.size(); ++j) {
if (cur[j] && p[cmp[v[i]]][cmp[j]] != 1) return 0;
if (!cur[j] && p[cmp[v[i]]][cmp[j]] != 2) return 0;
}
}
for (int i = 1; i < v.size(); ++i) {
ans[cmp[v[i]]][cmp[v[0]]] = ans[cmp[v[0]]][cmp[v[i]]] = 1;
}
rt.pb(v[0]);
}
for (int i = 0; i < rt.size() - 1; ++i) {
ans[cmp[rt[i]]][cmp[rt[i+1]]] = ans[cmp[rt[i+1]]][cmp[rt[i]]] = 1;
}
if(rt.size() > 1) ans[cmp[rt.back()]][cmp[rt[0]]] = ans[cmp[rt[0]]][cmp[rt.back()]] = 1;
return 1;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
vector<vector<int>> cmp;
vector<int> cmp_n(n , -1);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (p[i][j] == 3) return 0;
if (p[i][j] > 0){
if (cmp_n[i] != -1 && cmp_n[i] != cmp_n[j]) return 0;
if (cmp_n[i] != -1) continue;
cmp_n[i] = cmp_n[j];
cmp[cmp_n[i]].pb(i);
}
}
if (cmp_n[i] == -1) cmp_n[i] = cmp.size() , cmp.pb({i});
}
for (auto v : cmp){
if (!solve_cmp(v, p, ans)) return 0;
}
build(ans);
return 1;
}
/*
void solve() {
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tst; tst = 1;
//cin >> tst;
while (tst--){
solve();
}
return 0;
}
*/
Compilation message
supertrees.cpp: In function 'int solve_cmp(std::vector<int>&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)':
supertrees.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < cmp.size(); ++i) {
| ~~^~~~~~~~~~~~
supertrees.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
supertrees.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
supertrees.cpp:45:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int j = 0; j < cmp.size(); ++j) {
| ~~^~~~~~~~~~~~
supertrees.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 1; i < v.size(); ++i) {
| ~~^~~~~~~~~~
supertrees.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < rt.size() - 1; ++i) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1172 KB |
Output is correct |
7 |
Correct |
247 ms |
22040 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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1172 KB |
Output is correct |
7 |
Correct |
247 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1180 KB |
Output is correct |
13 |
Correct |
246 ms |
22000 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
110 ms |
12424 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
6044 KB |
Output is correct |
21 |
Correct |
242 ms |
22416 KB |
Output is correct |
22 |
Correct |
243 ms |
22340 KB |
Output is correct |
23 |
Correct |
254 ms |
23964 KB |
Output is correct |
24 |
Correct |
244 ms |
24004 KB |
Output is correct |
25 |
Correct |
106 ms |
14020 KB |
Output is correct |
26 |
Correct |
114 ms |
14060 KB |
Output is correct |
27 |
Correct |
249 ms |
23928 KB |
Output is correct |
28 |
Correct |
246 ms |
24044 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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1104 KB |
Output is correct |
9 |
Correct |
245 ms |
22084 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
242 ms |
21952 KB |
Output is correct |
14 |
Correct |
1 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 |
114 ms |
14076 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
6256 KB |
Output is correct |
22 |
Correct |
245 ms |
24064 KB |
Output is correct |
23 |
Correct |
242 ms |
24004 KB |
Output is correct |
24 |
Correct |
256 ms |
23992 KB |
Output is correct |
25 |
Correct |
104 ms |
14112 KB |
Output is correct |
26 |
Correct |
110 ms |
14076 KB |
Output is correct |
27 |
Correct |
247 ms |
23928 KB |
Output is correct |
28 |
Correct |
254 ms |
24084 KB |
Output is correct |
29 |
Correct |
107 ms |
14080 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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
60 ms |
5700 KB |
Output is correct |
5 |
Correct |
244 ms |
22016 KB |
Output is correct |
6 |
Correct |
242 ms |
21956 KB |
Output is correct |
7 |
Correct |
252 ms |
22024 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
66 ms |
5828 KB |
Output is correct |
10 |
Correct |
245 ms |
22032 KB |
Output is correct |
11 |
Correct |
239 ms |
22024 KB |
Output is correct |
12 |
Correct |
256 ms |
22000 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
63 ms |
5700 KB |
Output is correct |
17 |
Correct |
245 ms |
21956 KB |
Output is correct |
18 |
Correct |
248 ms |
22016 KB |
Output is correct |
19 |
Correct |
241 ms |
21956 KB |
Output is correct |
20 |
Correct |
247 ms |
22084 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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1172 KB |
Output is correct |
7 |
Correct |
247 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1180 KB |
Output is correct |
13 |
Correct |
246 ms |
22000 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
110 ms |
12424 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
6044 KB |
Output is correct |
21 |
Correct |
242 ms |
22416 KB |
Output is correct |
22 |
Correct |
243 ms |
22340 KB |
Output is correct |
23 |
Correct |
254 ms |
23964 KB |
Output is correct |
24 |
Correct |
244 ms |
24004 KB |
Output is correct |
25 |
Correct |
106 ms |
14020 KB |
Output is correct |
26 |
Correct |
114 ms |
14060 KB |
Output is correct |
27 |
Correct |
249 ms |
23928 KB |
Output is correct |
28 |
Correct |
246 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1104 KB |
Output is correct |
37 |
Correct |
245 ms |
22084 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
242 ms |
21952 KB |
Output is correct |
42 |
Correct |
1 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 |
114 ms |
14076 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
6256 KB |
Output is correct |
50 |
Correct |
245 ms |
24064 KB |
Output is correct |
51 |
Correct |
242 ms |
24004 KB |
Output is correct |
52 |
Correct |
256 ms |
23992 KB |
Output is correct |
53 |
Correct |
104 ms |
14112 KB |
Output is correct |
54 |
Correct |
110 ms |
14076 KB |
Output is correct |
55 |
Correct |
247 ms |
23928 KB |
Output is correct |
56 |
Correct |
254 ms |
24084 KB |
Output is correct |
57 |
Correct |
107 ms |
14080 KB |
Output is correct |
58 |
Correct |
1 ms |
208 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
6 ms |
792 KB |
Output is correct |
61 |
Correct |
112 ms |
14068 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
292 KB |
Output is correct |
64 |
Correct |
1 ms |
296 KB |
Output is correct |
65 |
Correct |
69 ms |
6256 KB |
Output is correct |
66 |
Correct |
107 ms |
14188 KB |
Output is correct |
67 |
Correct |
109 ms |
14076 KB |
Output is correct |
68 |
Correct |
109 ms |
14124 KB |
Output is correct |
69 |
Correct |
107 ms |
14076 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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1172 KB |
Output is correct |
7 |
Correct |
247 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1180 KB |
Output is correct |
13 |
Correct |
246 ms |
22000 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
110 ms |
12424 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
62 ms |
6044 KB |
Output is correct |
21 |
Correct |
242 ms |
22416 KB |
Output is correct |
22 |
Correct |
243 ms |
22340 KB |
Output is correct |
23 |
Correct |
254 ms |
23964 KB |
Output is correct |
24 |
Correct |
244 ms |
24004 KB |
Output is correct |
25 |
Correct |
106 ms |
14020 KB |
Output is correct |
26 |
Correct |
114 ms |
14060 KB |
Output is correct |
27 |
Correct |
249 ms |
23928 KB |
Output is correct |
28 |
Correct |
246 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1104 KB |
Output is correct |
37 |
Correct |
245 ms |
22084 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
242 ms |
21952 KB |
Output is correct |
42 |
Correct |
1 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 |
114 ms |
14076 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
6256 KB |
Output is correct |
50 |
Correct |
245 ms |
24064 KB |
Output is correct |
51 |
Correct |
242 ms |
24004 KB |
Output is correct |
52 |
Correct |
256 ms |
23992 KB |
Output is correct |
53 |
Correct |
104 ms |
14112 KB |
Output is correct |
54 |
Correct |
110 ms |
14076 KB |
Output is correct |
55 |
Correct |
247 ms |
23928 KB |
Output is correct |
56 |
Correct |
254 ms |
24084 KB |
Output is correct |
57 |
Correct |
107 ms |
14080 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
60 ms |
5700 KB |
Output is correct |
62 |
Correct |
244 ms |
22016 KB |
Output is correct |
63 |
Correct |
242 ms |
21956 KB |
Output is correct |
64 |
Correct |
252 ms |
22024 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
66 ms |
5828 KB |
Output is correct |
67 |
Correct |
245 ms |
22032 KB |
Output is correct |
68 |
Correct |
239 ms |
22024 KB |
Output is correct |
69 |
Correct |
256 ms |
22000 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
204 KB |
Output is correct |
73 |
Correct |
63 ms |
5700 KB |
Output is correct |
74 |
Correct |
245 ms |
21956 KB |
Output is correct |
75 |
Correct |
248 ms |
22016 KB |
Output is correct |
76 |
Correct |
241 ms |
21956 KB |
Output is correct |
77 |
Correct |
247 ms |
22084 KB |
Output is correct |
78 |
Correct |
1 ms |
208 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
6 ms |
792 KB |
Output is correct |
81 |
Correct |
112 ms |
14068 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
292 KB |
Output is correct |
84 |
Correct |
1 ms |
296 KB |
Output is correct |
85 |
Correct |
69 ms |
6256 KB |
Output is correct |
86 |
Correct |
107 ms |
14188 KB |
Output is correct |
87 |
Correct |
109 ms |
14076 KB |
Output is correct |
88 |
Correct |
109 ms |
14124 KB |
Output is correct |
89 |
Correct |
107 ms |
14076 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
844 KB |
Output is correct |
93 |
Correct |
106 ms |
14076 KB |
Output is correct |
94 |
Correct |
1 ms |
296 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
27 ms |
3696 KB |
Output is correct |
98 |
Correct |
110 ms |
14072 KB |
Output is correct |
99 |
Correct |
107 ms |
14020 KB |
Output is correct |
100 |
Correct |
108 ms |
14020 KB |
Output is correct |
101 |
Correct |
104 ms |
14020 KB |
Output is correct |
102 |
Correct |
109 ms |
14064 KB |
Output is correct |
103 |
Correct |
103 ms |
14076 KB |
Output is correct |
104 |
Correct |
106 ms |
14076 KB |
Output is correct |
105 |
Correct |
110 ms |
14064 KB |
Output is correct |