#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void build(std::vector<std::vector<int>> b);
int construct(vector<vector<int>> arr) {
for (auto& a : arr) {
for (auto& b : a) {
if (b == 3) {
return 0;
}
}
}
int n = sz(arr);
bool vis[n] {};
vector<vector<int>> trees;
for (int i = 0; i < n; i++) {
if (vis[i]) {
continue;
}
vis[i] = true;
trees.push_back({i});
for (int j = 0; j < n; j++) {
if (!vis[j] && arr[i][j] == 1) {
trees.back().push_back(j);
vis[j] = true;
}
}
}
vector<vector<int>> cycles;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < sz(trees); i++) {
if (vis[i]) {
continue;
}
vis[i] = true;
cycles.push_back({i});
for (int j = 0; j < sz(trees); j++) {
if (!vis[j] && arr[trees[i][0]][trees[j][0]] == 2) {
cycles.back().push_back(j);
vis[j] = true;
}
}
if (sz(cycles.back()) == 2) {
return 0;
}
}
int rtree[n], rcycle1[n], rcycle[n];
for (int i = 0; i < sz(trees); i++) {
for (auto& a : trees[i]) {
rtree[a] = i;
}
}
for (int i = 0; i < sz(cycles); i++) {
for (auto& a : cycles[i]) {
rcycle1[a] = i;
}
}
for (int i = 0; i < n; i++) {
rcycle[i] = rcycle1[rtree[i]];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int x;
if (rtree[i] == rtree[j]) {
x = 1;
} else if (rcycle[i] == rcycle[j]) {
x = 2;
} else {
x = 0;
}
if (arr[i][j] != x) {
return 0;
}
}
}
vector<vector<int>> graph(n, vector<int>(n));
auto add_edge = [&](int u, int v) -> void {
graph[u][v] = graph[v][u] = true;
};
for (auto& a : trees) {
for (int i = 1; i < sz(a); i++) {
add_edge(a[0], a[i]);
}
}
for (auto& a : cycles) {
if (sz(a) == 1) {
continue;
}
for (int i = 0; i < sz(a); i++) {
add_edge(trees[a[i]][0], trees[a[(i + 1) % sz(a)]][0]);
}
}
build(graph);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
1232 KB |
Output is correct |
7 |
Correct |
182 ms |
22712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
1232 KB |
Output is correct |
7 |
Correct |
182 ms |
22712 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
185 ms |
22720 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
700 KB |
Output is correct |
17 |
Correct |
73 ms |
8772 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6176 KB |
Output is correct |
21 |
Correct |
194 ms |
22596 KB |
Output is correct |
22 |
Correct |
198 ms |
22724 KB |
Output is correct |
23 |
Correct |
181 ms |
22684 KB |
Output is correct |
24 |
Correct |
185 ms |
22696 KB |
Output is correct |
25 |
Correct |
66 ms |
8712 KB |
Output is correct |
26 |
Correct |
90 ms |
8804 KB |
Output is correct |
27 |
Correct |
208 ms |
22612 KB |
Output is correct |
28 |
Correct |
172 ms |
22804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 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 |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1236 KB |
Output is correct |
9 |
Correct |
173 ms |
22788 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
1204 KB |
Output is correct |
13 |
Correct |
177 ms |
22752 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
692 KB |
Output is correct |
17 |
Correct |
75 ms |
8852 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
54 ms |
6220 KB |
Output is correct |
22 |
Correct |
181 ms |
22660 KB |
Output is correct |
23 |
Correct |
250 ms |
22732 KB |
Output is correct |
24 |
Correct |
212 ms |
22760 KB |
Output is correct |
25 |
Correct |
77 ms |
8920 KB |
Output is correct |
26 |
Correct |
72 ms |
8828 KB |
Output is correct |
27 |
Correct |
202 ms |
22656 KB |
Output is correct |
28 |
Correct |
187 ms |
22704 KB |
Output is correct |
29 |
Correct |
71 ms |
8840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
49 ms |
6168 KB |
Output is correct |
5 |
Correct |
189 ms |
22668 KB |
Output is correct |
6 |
Correct |
181 ms |
22688 KB |
Output is correct |
7 |
Correct |
186 ms |
22604 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
48 ms |
6288 KB |
Output is correct |
10 |
Correct |
189 ms |
22732 KB |
Output is correct |
11 |
Correct |
187 ms |
22732 KB |
Output is correct |
12 |
Correct |
194 ms |
22712 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
45 ms |
6204 KB |
Output is correct |
17 |
Correct |
171 ms |
22912 KB |
Output is correct |
18 |
Correct |
203 ms |
22976 KB |
Output is correct |
19 |
Correct |
170 ms |
22916 KB |
Output is correct |
20 |
Correct |
183 ms |
22992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
1232 KB |
Output is correct |
7 |
Correct |
182 ms |
22712 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
185 ms |
22720 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
700 KB |
Output is correct |
17 |
Correct |
73 ms |
8772 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6176 KB |
Output is correct |
21 |
Correct |
194 ms |
22596 KB |
Output is correct |
22 |
Correct |
198 ms |
22724 KB |
Output is correct |
23 |
Correct |
181 ms |
22684 KB |
Output is correct |
24 |
Correct |
185 ms |
22696 KB |
Output is correct |
25 |
Correct |
66 ms |
8712 KB |
Output is correct |
26 |
Correct |
90 ms |
8804 KB |
Output is correct |
27 |
Correct |
208 ms |
22612 KB |
Output is correct |
28 |
Correct |
172 ms |
22804 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
300 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 |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
173 ms |
22788 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1204 KB |
Output is correct |
41 |
Correct |
177 ms |
22752 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
692 KB |
Output is correct |
45 |
Correct |
75 ms |
8852 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
54 ms |
6220 KB |
Output is correct |
50 |
Correct |
181 ms |
22660 KB |
Output is correct |
51 |
Correct |
250 ms |
22732 KB |
Output is correct |
52 |
Correct |
212 ms |
22760 KB |
Output is correct |
53 |
Correct |
77 ms |
8920 KB |
Output is correct |
54 |
Correct |
72 ms |
8828 KB |
Output is correct |
55 |
Correct |
202 ms |
22656 KB |
Output is correct |
56 |
Correct |
187 ms |
22704 KB |
Output is correct |
57 |
Correct |
71 ms |
8840 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
692 KB |
Output is correct |
61 |
Correct |
71 ms |
8704 KB |
Output is correct |
62 |
Correct |
1 ms |
300 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
45 ms |
6188 KB |
Output is correct |
66 |
Correct |
68 ms |
9096 KB |
Output is correct |
67 |
Correct |
78 ms |
9104 KB |
Output is correct |
68 |
Correct |
66 ms |
9096 KB |
Output is correct |
69 |
Correct |
69 ms |
9076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
1232 KB |
Output is correct |
7 |
Correct |
182 ms |
22712 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
185 ms |
22720 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
700 KB |
Output is correct |
17 |
Correct |
73 ms |
8772 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6176 KB |
Output is correct |
21 |
Correct |
194 ms |
22596 KB |
Output is correct |
22 |
Correct |
198 ms |
22724 KB |
Output is correct |
23 |
Correct |
181 ms |
22684 KB |
Output is correct |
24 |
Correct |
185 ms |
22696 KB |
Output is correct |
25 |
Correct |
66 ms |
8712 KB |
Output is correct |
26 |
Correct |
90 ms |
8804 KB |
Output is correct |
27 |
Correct |
208 ms |
22612 KB |
Output is correct |
28 |
Correct |
172 ms |
22804 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
300 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 |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
173 ms |
22788 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1204 KB |
Output is correct |
41 |
Correct |
177 ms |
22752 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
692 KB |
Output is correct |
45 |
Correct |
75 ms |
8852 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
54 ms |
6220 KB |
Output is correct |
50 |
Correct |
181 ms |
22660 KB |
Output is correct |
51 |
Correct |
250 ms |
22732 KB |
Output is correct |
52 |
Correct |
212 ms |
22760 KB |
Output is correct |
53 |
Correct |
77 ms |
8920 KB |
Output is correct |
54 |
Correct |
72 ms |
8828 KB |
Output is correct |
55 |
Correct |
202 ms |
22656 KB |
Output is correct |
56 |
Correct |
187 ms |
22704 KB |
Output is correct |
57 |
Correct |
71 ms |
8840 KB |
Output is correct |
58 |
Correct |
1 ms |
300 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
296 KB |
Output is correct |
61 |
Correct |
49 ms |
6168 KB |
Output is correct |
62 |
Correct |
189 ms |
22668 KB |
Output is correct |
63 |
Correct |
181 ms |
22688 KB |
Output is correct |
64 |
Correct |
186 ms |
22604 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
48 ms |
6288 KB |
Output is correct |
67 |
Correct |
189 ms |
22732 KB |
Output is correct |
68 |
Correct |
187 ms |
22732 KB |
Output is correct |
69 |
Correct |
194 ms |
22712 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
45 ms |
6204 KB |
Output is correct |
74 |
Correct |
171 ms |
22912 KB |
Output is correct |
75 |
Correct |
203 ms |
22976 KB |
Output is correct |
76 |
Correct |
170 ms |
22916 KB |
Output is correct |
77 |
Correct |
183 ms |
22992 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
692 KB |
Output is correct |
81 |
Correct |
71 ms |
8704 KB |
Output is correct |
82 |
Correct |
1 ms |
300 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
45 ms |
6188 KB |
Output is correct |
86 |
Correct |
68 ms |
9096 KB |
Output is correct |
87 |
Correct |
78 ms |
9104 KB |
Output is correct |
88 |
Correct |
66 ms |
9096 KB |
Output is correct |
89 |
Correct |
69 ms |
9076 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
296 KB |
Output is correct |
92 |
Correct |
3 ms |
696 KB |
Output is correct |
93 |
Correct |
71 ms |
8996 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
300 KB |
Output is correct |
97 |
Correct |
16 ms |
2676 KB |
Output is correct |
98 |
Correct |
68 ms |
10048 KB |
Output is correct |
99 |
Correct |
73 ms |
10088 KB |
Output is correct |
100 |
Correct |
82 ms |
10080 KB |
Output is correct |
101 |
Correct |
68 ms |
10088 KB |
Output is correct |
102 |
Correct |
63 ms |
10076 KB |
Output is correct |
103 |
Correct |
65 ms |
10064 KB |
Output is correct |
104 |
Correct |
80 ms |
9984 KB |
Output is correct |
105 |
Correct |
78 ms |
10100 KB |
Output is correct |