#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "supertrees.h"
#else
void build(vector<vector<int>> b) {
int n = b.size();
cout << "________" << endl;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
cout << b[i][j] << " ";
}
cout << endl;
}
cout << endl;
for(int i = 0; i < n; ++i) {
for(int j = i; j < n; ++j) {
if(b[i][j]) {
cout << i << " - " << j << endl;
}
}
}
}
#endif
const int N = 1003;
int dop[N];
int P(int x) {
return (dop[x] ^ -1 ? dop[x] = P(dop[x]) : x);
}
void U(int x, int y) {
dop[P(x)] = (P(x) ^ P(y) ? P(y) : -1);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> b(n);
for(int i = 0; i < n; ++i) {
dop[i] = -1;
b[i].resize(n);
}
// // // // // // // //
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(p[i][j] == 3) return 0;
if(p[i][j] == 1) U(i, j);
}
}
vector<int> dopn(n, -1), ep(n);
vector<vector<int>> v;
for(int i = 0; i < n; ++i) {
ep[i] = P(i);
if(dopn[P(i)] == -1) {
dopn[P(i)] = v.size();
v.push_back({});
}
v[dopn[P(i)]].push_back(i);
if(p[v[dopn[P(i)]][0]] != p[i]) return 0;
}
int m = v.size();
for(int i = 0; i < m; ++i) {
for(int j = 1; j < (int)v[i].size(); ++j) {
b[v[i][j - 1]][v[i][j]] = 1;
b[v[i][j]][v[i][j - 1]] = 1;
}
}
// // // // // // // //
for(int i = 0; i < m; ++i) {
dop[i] = -1;
}
// // // // // // // //
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(p[i][j] == 2) U(dopn[ep[i]], dopn[ep[j]]);
}
}
vector<vector<int>> q = p;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(q[i][j] == 1) q[i][j] = 2;
}
}
vector<int> dopm(n, -1);
vector<vector<int>> u;
for(int i = 0; i < m; ++i) {
if(dopm[P(i)] == -1) {
dopm[P(i)] = u.size();
u.push_back({});
}
u[dopm[P(i)]].push_back(i);
if(q[v[u[dopm[P(i)]][0]][0]] != q[v[i][0]]) return 0;
}
int k = u.size();
for(int i = 0; i < k; ++i) {
if(u[i].size() == 1) continue;
if(u[i].size() == 2) return 0;
for(int j = 1; j < (int)u[i].size(); ++j) {
int x = u[i][j], y = u[i][j - 1];
b[v[x][0]][v[y][0]] = 1;
b[v[y][0]][v[x][0]] = 1;
}
int x = u[i][0], y = u[i][(int)u[i].size() - 1];
b[v[x][0]][v[y][0]] = 1;
b[v[y][0]][v[x][0]] = 1;
}
build(b);
return 1;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}) << endl << "________" << endl;
cout << construct({{1, 0}, {0, 1}}) << endl << "________" << endl;
cout << construct({{1, 3}, {3, 1}}) << endl << "________" << endl;
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1516 KB |
Output is correct |
7 |
Correct |
256 ms |
28116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1516 KB |
Output is correct |
7 |
Correct |
256 ms |
28116 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1516 KB |
Output is correct |
13 |
Correct |
254 ms |
28140 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
14188 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
7276 KB |
Output is correct |
21 |
Correct |
255 ms |
28032 KB |
Output is correct |
22 |
Correct |
251 ms |
28268 KB |
Output is correct |
23 |
Correct |
267 ms |
28012 KB |
Output is correct |
24 |
Correct |
250 ms |
28140 KB |
Output is correct |
25 |
Correct |
108 ms |
14188 KB |
Output is correct |
26 |
Correct |
103 ms |
14188 KB |
Output is correct |
27 |
Correct |
265 ms |
28244 KB |
Output is correct |
28 |
Correct |
250 ms |
28140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1516 KB |
Output is correct |
9 |
Correct |
254 ms |
28244 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1516 KB |
Output is correct |
13 |
Correct |
254 ms |
28140 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
122 ms |
18028 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
66 ms |
7404 KB |
Output is correct |
22 |
Correct |
254 ms |
28140 KB |
Output is correct |
23 |
Correct |
250 ms |
28064 KB |
Output is correct |
24 |
Correct |
265 ms |
28268 KB |
Output is correct |
25 |
Correct |
113 ms |
18156 KB |
Output is correct |
26 |
Correct |
112 ms |
18156 KB |
Output is correct |
27 |
Correct |
254 ms |
28064 KB |
Output is correct |
28 |
Correct |
269 ms |
28140 KB |
Output is correct |
29 |
Correct |
107 ms |
18156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
64 ms |
7276 KB |
Output is correct |
5 |
Correct |
256 ms |
28140 KB |
Output is correct |
6 |
Correct |
256 ms |
28140 KB |
Output is correct |
7 |
Correct |
268 ms |
28012 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
65 ms |
7404 KB |
Output is correct |
10 |
Correct |
254 ms |
28140 KB |
Output is correct |
11 |
Correct |
254 ms |
28140 KB |
Output is correct |
12 |
Correct |
268 ms |
28140 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
63 ms |
7404 KB |
Output is correct |
17 |
Correct |
256 ms |
28140 KB |
Output is correct |
18 |
Correct |
254 ms |
28012 KB |
Output is correct |
19 |
Correct |
257 ms |
28140 KB |
Output is correct |
20 |
Correct |
251 ms |
28244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1516 KB |
Output is correct |
7 |
Correct |
256 ms |
28116 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1516 KB |
Output is correct |
13 |
Correct |
254 ms |
28140 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
14188 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
7276 KB |
Output is correct |
21 |
Correct |
255 ms |
28032 KB |
Output is correct |
22 |
Correct |
251 ms |
28268 KB |
Output is correct |
23 |
Correct |
267 ms |
28012 KB |
Output is correct |
24 |
Correct |
250 ms |
28140 KB |
Output is correct |
25 |
Correct |
108 ms |
14188 KB |
Output is correct |
26 |
Correct |
103 ms |
14188 KB |
Output is correct |
27 |
Correct |
265 ms |
28244 KB |
Output is correct |
28 |
Correct |
250 ms |
28140 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
0 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1516 KB |
Output is correct |
37 |
Correct |
254 ms |
28244 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1516 KB |
Output is correct |
41 |
Correct |
254 ms |
28140 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
1004 KB |
Output is correct |
45 |
Correct |
122 ms |
18028 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
66 ms |
7404 KB |
Output is correct |
50 |
Correct |
254 ms |
28140 KB |
Output is correct |
51 |
Correct |
250 ms |
28064 KB |
Output is correct |
52 |
Correct |
265 ms |
28268 KB |
Output is correct |
53 |
Correct |
113 ms |
18156 KB |
Output is correct |
54 |
Correct |
112 ms |
18156 KB |
Output is correct |
55 |
Correct |
254 ms |
28064 KB |
Output is correct |
56 |
Correct |
269 ms |
28140 KB |
Output is correct |
57 |
Correct |
107 ms |
18156 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
876 KB |
Output is correct |
61 |
Correct |
117 ms |
14188 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
65 ms |
7404 KB |
Output is correct |
66 |
Correct |
113 ms |
14188 KB |
Output is correct |
67 |
Correct |
105 ms |
14188 KB |
Output is correct |
68 |
Correct |
105 ms |
14316 KB |
Output is correct |
69 |
Correct |
107 ms |
18180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1516 KB |
Output is correct |
7 |
Correct |
256 ms |
28116 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1516 KB |
Output is correct |
13 |
Correct |
254 ms |
28140 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
14188 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
7276 KB |
Output is correct |
21 |
Correct |
255 ms |
28032 KB |
Output is correct |
22 |
Correct |
251 ms |
28268 KB |
Output is correct |
23 |
Correct |
267 ms |
28012 KB |
Output is correct |
24 |
Correct |
250 ms |
28140 KB |
Output is correct |
25 |
Correct |
108 ms |
14188 KB |
Output is correct |
26 |
Correct |
103 ms |
14188 KB |
Output is correct |
27 |
Correct |
265 ms |
28244 KB |
Output is correct |
28 |
Correct |
250 ms |
28140 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
0 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1516 KB |
Output is correct |
37 |
Correct |
254 ms |
28244 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1516 KB |
Output is correct |
41 |
Correct |
254 ms |
28140 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
1004 KB |
Output is correct |
45 |
Correct |
122 ms |
18028 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
66 ms |
7404 KB |
Output is correct |
50 |
Correct |
254 ms |
28140 KB |
Output is correct |
51 |
Correct |
250 ms |
28064 KB |
Output is correct |
52 |
Correct |
265 ms |
28268 KB |
Output is correct |
53 |
Correct |
113 ms |
18156 KB |
Output is correct |
54 |
Correct |
112 ms |
18156 KB |
Output is correct |
55 |
Correct |
254 ms |
28064 KB |
Output is correct |
56 |
Correct |
269 ms |
28140 KB |
Output is correct |
57 |
Correct |
107 ms |
18156 KB |
Output is correct |
58 |
Correct |
0 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
64 ms |
7276 KB |
Output is correct |
62 |
Correct |
256 ms |
28140 KB |
Output is correct |
63 |
Correct |
256 ms |
28140 KB |
Output is correct |
64 |
Correct |
268 ms |
28012 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
65 ms |
7404 KB |
Output is correct |
67 |
Correct |
254 ms |
28140 KB |
Output is correct |
68 |
Correct |
254 ms |
28140 KB |
Output is correct |
69 |
Correct |
268 ms |
28140 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
63 ms |
7404 KB |
Output is correct |
74 |
Correct |
256 ms |
28140 KB |
Output is correct |
75 |
Correct |
254 ms |
28012 KB |
Output is correct |
76 |
Correct |
257 ms |
28140 KB |
Output is correct |
77 |
Correct |
251 ms |
28244 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
876 KB |
Output is correct |
81 |
Correct |
117 ms |
14188 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
65 ms |
7404 KB |
Output is correct |
86 |
Correct |
113 ms |
14188 KB |
Output is correct |
87 |
Correct |
105 ms |
14188 KB |
Output is correct |
88 |
Correct |
105 ms |
14316 KB |
Output is correct |
89 |
Correct |
107 ms |
18180 KB |
Output is correct |
90 |
Correct |
0 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
876 KB |
Output is correct |
93 |
Correct |
100 ms |
14060 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
27 ms |
3820 KB |
Output is correct |
98 |
Correct |
103 ms |
14188 KB |
Output is correct |
99 |
Correct |
102 ms |
14060 KB |
Output is correct |
100 |
Correct |
105 ms |
14060 KB |
Output is correct |
101 |
Correct |
105 ms |
14060 KB |
Output is correct |
102 |
Correct |
94 ms |
14060 KB |
Output is correct |
103 |
Correct |
92 ms |
14060 KB |
Output is correct |
104 |
Correct |
94 ms |
14188 KB |
Output is correct |
105 |
Correct |
108 ms |
14188 KB |
Output is correct |