#include "supertrees.h"
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
#define f0(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
f0(i, n) {
f0(j, n) {
if(p[i][j] == 3) {
return 0;
}
if(p[i][j] != p[j][i]) {
return 0;
}
}
if(p[i][i] != 1) {
return 0;
}
}
// okay
vector<vector<pair<int, int>>> graph(n);
f0(i, n) {
f0(j, n) {
if(p[i][j] == 0) continue;
if(i == j) continue;
graph[i].push_back({p[i][j], j});
}
}
f0(i, n) {
sort(graph[i].begin(), graph[i].end());
}
// okay
std::vector<std::vector<int>> b;
for (int i = 0; i < n; i++) {
std::vector<int> row(n, 0);
row.resize(n);
b.push_back(row);
}
// okay
vector<vector<int>> groups;
bool used[n] = {0};
f0(i, n) {
if(used[i]) continue;
vector<int> group;
group.push_back(i);
used[i] = true;
queue<int> q;
q.push(i);
while(!q.empty()) {
int u = q.front();
q.pop();
for(auto v : graph[u]) {
if(used[v.second]) continue;
used[v.second] = true;
group.push_back(v.second);
q.push(v.second);
}
}
for(int u: group) {
for(int v: group) {
if(p[u][v] == 0) {
return 0;
}
}
}
groups.push_back(group);
}
// okay
for(auto group : groups) {
vector<vector<int>> g;
for(int i : group) {
if(!used[i]) continue;
vector<int> gg;
gg.push_back(i);
used[i] = false;
for(auto pp: graph[i]) {
if(pp.first == 2) break;
gg.push_back(pp.second);
used[pp.second] = false;
}
g.push_back(gg);
}
// okay
// for(auto gg: g) {
// for(int i: gg) {
// cout << i << " ";
// }
// cout << endl;
// }
int nn = g.size();
if(nn == 2) return 0;
f0(i, nn) {
if(nn != 1) {
b[g[i][0]][g[(i+1)%nn][0]] = 1;
b[g[(i+1)%nn][0]][g[i][0]] = 1;
}
int nnn = g[i].size();
f1(j, nnn-1) {
b[g[i][j]][g[i][j-1]] = 1;
b[g[i][j-1]][g[i][j]] = 1;
}
}
// okay
f0(i, nn) {
for(int j = i+1; j < nn; j++) {
for(int u: g[i]) {
for(int v: g[j]) {
if(p[u][v] != 2) {
return 0;
}
if(p[v][u] != 2) {
return 0;
}
}
}
}
for(int u: g[i]) {
for(int v: g[i]) {
if(p[u][v] != 1) {
return 0;
}
}
}
}
}
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
191 ms |
30036 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 |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
191 ms |
30036 KB |
Output is correct |
8 |
Correct |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
161 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
97 ms |
17028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
23040 KB |
Output is correct |
22 |
Correct |
165 ms |
22192 KB |
Output is correct |
23 |
Correct |
179 ms |
26000 KB |
Output is correct |
24 |
Correct |
168 ms |
22132 KB |
Output is correct |
25 |
Correct |
70 ms |
13060 KB |
Output is correct |
26 |
Correct |
65 ms |
12144 KB |
Output is correct |
27 |
Correct |
184 ms |
28060 KB |
Output is correct |
28 |
Correct |
162 ms |
22068 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
174 ms |
24012 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1620 KB |
Output is correct |
13 |
Correct |
196 ms |
32208 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
91 ms |
18936 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
44 ms |
6260 KB |
Output is correct |
22 |
Correct |
166 ms |
24940 KB |
Output is correct |
23 |
Correct |
159 ms |
24012 KB |
Output is correct |
24 |
Correct |
186 ms |
30072 KB |
Output is correct |
25 |
Correct |
66 ms |
14068 KB |
Output is correct |
26 |
Correct |
71 ms |
15096 KB |
Output is correct |
27 |
Correct |
161 ms |
24072 KB |
Output is correct |
28 |
Correct |
194 ms |
28004 KB |
Output is correct |
29 |
Correct |
68 ms |
14076 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 |
42 ms |
5816 KB |
Output is correct |
5 |
Correct |
163 ms |
23052 KB |
Output is correct |
6 |
Correct |
172 ms |
22288 KB |
Output is correct |
7 |
Correct |
182 ms |
26000 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
40 ms |
5832 KB |
Output is correct |
10 |
Correct |
167 ms |
23056 KB |
Output is correct |
11 |
Correct |
158 ms |
22148 KB |
Output is correct |
12 |
Correct |
184 ms |
28120 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
41 ms |
5824 KB |
Output is correct |
17 |
Correct |
165 ms |
22988 KB |
Output is correct |
18 |
Correct |
164 ms |
22976 KB |
Output is correct |
19 |
Correct |
159 ms |
22464 KB |
Output is correct |
20 |
Correct |
157 ms |
22032 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 |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
191 ms |
30036 KB |
Output is correct |
8 |
Correct |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
161 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
97 ms |
17028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
23040 KB |
Output is correct |
22 |
Correct |
165 ms |
22192 KB |
Output is correct |
23 |
Correct |
179 ms |
26000 KB |
Output is correct |
24 |
Correct |
168 ms |
22132 KB |
Output is correct |
25 |
Correct |
70 ms |
13060 KB |
Output is correct |
26 |
Correct |
65 ms |
12144 KB |
Output is correct |
27 |
Correct |
184 ms |
28060 KB |
Output is correct |
28 |
Correct |
162 ms |
22068 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 |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
174 ms |
24012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1620 KB |
Output is correct |
41 |
Correct |
196 ms |
32208 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
91 ms |
18936 KB |
Output is correct |
46 |
Correct |
1 ms |
300 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
6260 KB |
Output is correct |
50 |
Correct |
166 ms |
24940 KB |
Output is correct |
51 |
Correct |
159 ms |
24012 KB |
Output is correct |
52 |
Correct |
186 ms |
30072 KB |
Output is correct |
53 |
Correct |
66 ms |
14068 KB |
Output is correct |
54 |
Correct |
71 ms |
15096 KB |
Output is correct |
55 |
Correct |
161 ms |
24072 KB |
Output is correct |
56 |
Correct |
194 ms |
28004 KB |
Output is correct |
57 |
Correct |
68 ms |
14076 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
5 ms |
1236 KB |
Output is correct |
61 |
Correct |
118 ms |
22068 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
46 ms |
6260 KB |
Output is correct |
66 |
Correct |
71 ms |
15228 KB |
Output is correct |
67 |
Correct |
75 ms |
15088 KB |
Output is correct |
68 |
Correct |
74 ms |
14412 KB |
Output is correct |
69 |
Correct |
67 ms |
14068 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 |
8 ms |
1492 KB |
Output is correct |
7 |
Correct |
191 ms |
30036 KB |
Output is correct |
8 |
Correct |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
161 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
97 ms |
17028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5836 KB |
Output is correct |
21 |
Correct |
161 ms |
23040 KB |
Output is correct |
22 |
Correct |
165 ms |
22192 KB |
Output is correct |
23 |
Correct |
179 ms |
26000 KB |
Output is correct |
24 |
Correct |
168 ms |
22132 KB |
Output is correct |
25 |
Correct |
70 ms |
13060 KB |
Output is correct |
26 |
Correct |
65 ms |
12144 KB |
Output is correct |
27 |
Correct |
184 ms |
28060 KB |
Output is correct |
28 |
Correct |
162 ms |
22068 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 |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
174 ms |
24012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1620 KB |
Output is correct |
41 |
Correct |
196 ms |
32208 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
91 ms |
18936 KB |
Output is correct |
46 |
Correct |
1 ms |
300 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
6260 KB |
Output is correct |
50 |
Correct |
166 ms |
24940 KB |
Output is correct |
51 |
Correct |
159 ms |
24012 KB |
Output is correct |
52 |
Correct |
186 ms |
30072 KB |
Output is correct |
53 |
Correct |
66 ms |
14068 KB |
Output is correct |
54 |
Correct |
71 ms |
15096 KB |
Output is correct |
55 |
Correct |
161 ms |
24072 KB |
Output is correct |
56 |
Correct |
194 ms |
28004 KB |
Output is correct |
57 |
Correct |
68 ms |
14076 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 |
42 ms |
5816 KB |
Output is correct |
62 |
Correct |
163 ms |
23052 KB |
Output is correct |
63 |
Correct |
172 ms |
22288 KB |
Output is correct |
64 |
Correct |
182 ms |
26000 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
40 ms |
5832 KB |
Output is correct |
67 |
Correct |
167 ms |
23056 KB |
Output is correct |
68 |
Correct |
158 ms |
22148 KB |
Output is correct |
69 |
Correct |
184 ms |
28120 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
41 ms |
5824 KB |
Output is correct |
74 |
Correct |
165 ms |
22988 KB |
Output is correct |
75 |
Correct |
164 ms |
22976 KB |
Output is correct |
76 |
Correct |
159 ms |
22464 KB |
Output is correct |
77 |
Correct |
157 ms |
22032 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
5 ms |
1236 KB |
Output is correct |
81 |
Correct |
118 ms |
22068 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
46 ms |
6260 KB |
Output is correct |
86 |
Correct |
71 ms |
15228 KB |
Output is correct |
87 |
Correct |
75 ms |
15088 KB |
Output is correct |
88 |
Correct |
74 ms |
14412 KB |
Output is correct |
89 |
Correct |
67 ms |
14068 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
300 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
69 ms |
10104 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
17 ms |
2772 KB |
Output is correct |
98 |
Correct |
67 ms |
10096 KB |
Output is correct |
99 |
Correct |
66 ms |
10096 KB |
Output is correct |
100 |
Correct |
66 ms |
10112 KB |
Output is correct |
101 |
Correct |
62 ms |
10100 KB |
Output is correct |
102 |
Correct |
62 ms |
10100 KB |
Output is correct |
103 |
Correct |
62 ms |
10108 KB |
Output is correct |
104 |
Correct |
66 ms |
10188 KB |
Output is correct |
105 |
Correct |
71 ms |
10112 KB |
Output is correct |