#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif
using namespace std;
const bool __initialization = []() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << setprecision(12) << fixed;
return true;
}();
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)
template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }
constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
#include "supertrees.h"
constexpr int maxn = 3e5 + 5;
struct UF {
vector<int> e;
UF(int n) : e(n, -1) {}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
int construct(vector<vector<int>> req) {
int n = req.size();
vector<vector<int>> ans(n, vector<int>(n));
UF dsu(n);
Rep (i, n) {
For (j, i + 1, n - 1) {
if (req[i][j] == 3) {
debug("3");
return false;
}
}
}
// forest
Rep (i, n) {
For (j, i + 1, n - 1) {
if (req[i][j] == 1) {
dsu.join(i, j);
}
}
}
Rep (i, n) {
For (j, i + 1, n - 1) {
if (dsu.sameSet(i, j) != (req[i][j] == 1)) {
debug("same != req (forest)");
return false;
}
}
}
vector<bool> root(n);
Rep (i, n) {
int u = dsu.find(i);
if (u != i) {
ans[u][i] = ans[i][u] = true;
}
else {
root[i] = true;
}
}
// cycle
Rep (i, n) {
For (j, i + 1, n - 1) {
if (req[i][j] == 2) {
dsu.join(i, j);
}
}
}
Rep (i, n) {
For (j, i + 1, n - 1) {
if (dsu.sameSet(i, j) != (req[i][j] != 0)) {
debug("same != req (cycle)");
return false;
}
}
}
// combine
Rep (i, n) {
if (!root[i]) continue;
root[i] = false;
int sz = 1;
int k = i;
Rep (j, n) {
if (root[j] && dsu.sameSet(i, j)) {
root[j] = false;
++sz;
ans[j][k] = ans[k][j] = true;
k = j;
}
}
if (sz == 2) {
debug("cycle size 2");
return false;
}
if (k != i) {
ans[i][k] = ans[k][i] = true;
}
}
return build(ans), true;
}
// does oj.uz allow IOI-style scoring?
// no
# |
Verdict |
Execution time |
Memory |
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 |
8 ms |
1156 KB |
Output is correct |
7 |
Correct |
162 ms |
22996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
8 ms |
1156 KB |
Output is correct |
7 |
Correct |
162 ms |
22996 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
170 ms |
22948 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
80 ms |
13352 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
42 ms |
6028 KB |
Output is correct |
21 |
Correct |
168 ms |
23200 KB |
Output is correct |
22 |
Correct |
162 ms |
23260 KB |
Output is correct |
23 |
Correct |
206 ms |
23308 KB |
Output is correct |
24 |
Correct |
164 ms |
23236 KB |
Output is correct |
25 |
Correct |
75 ms |
13292 KB |
Output is correct |
26 |
Correct |
78 ms |
13380 KB |
Output is correct |
27 |
Correct |
178 ms |
23256 KB |
Output is correct |
28 |
Correct |
166 ms |
23364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
9 ms |
1172 KB |
Output is correct |
9 |
Correct |
163 ms |
22052 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1188 KB |
Output is correct |
13 |
Correct |
162 ms |
22048 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
78 ms |
13344 KB |
Output is correct |
18 |
Correct |
1 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 |
50 ms |
5856 KB |
Output is correct |
22 |
Correct |
162 ms |
23344 KB |
Output is correct |
23 |
Correct |
166 ms |
23236 KB |
Output is correct |
24 |
Correct |
172 ms |
23304 KB |
Output is correct |
25 |
Correct |
79 ms |
13388 KB |
Output is correct |
26 |
Correct |
71 ms |
13452 KB |
Output is correct |
27 |
Correct |
159 ms |
23304 KB |
Output is correct |
28 |
Correct |
176 ms |
23196 KB |
Output is correct |
29 |
Correct |
74 ms |
13348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
42 ms |
5732 KB |
Output is correct |
5 |
Correct |
162 ms |
22024 KB |
Output is correct |
6 |
Correct |
164 ms |
22052 KB |
Output is correct |
7 |
Correct |
171 ms |
21956 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
46 ms |
5780 KB |
Output is correct |
10 |
Correct |
165 ms |
22036 KB |
Output is correct |
11 |
Correct |
160 ms |
21956 KB |
Output is correct |
12 |
Correct |
177 ms |
22032 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
41 ms |
5700 KB |
Output is correct |
17 |
Correct |
161 ms |
22048 KB |
Output is correct |
18 |
Correct |
162 ms |
22044 KB |
Output is correct |
19 |
Correct |
159 ms |
21956 KB |
Output is correct |
20 |
Correct |
186 ms |
21956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
8 ms |
1156 KB |
Output is correct |
7 |
Correct |
162 ms |
22996 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
170 ms |
22948 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
80 ms |
13352 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
42 ms |
6028 KB |
Output is correct |
21 |
Correct |
168 ms |
23200 KB |
Output is correct |
22 |
Correct |
162 ms |
23260 KB |
Output is correct |
23 |
Correct |
206 ms |
23308 KB |
Output is correct |
24 |
Correct |
164 ms |
23236 KB |
Output is correct |
25 |
Correct |
75 ms |
13292 KB |
Output is correct |
26 |
Correct |
78 ms |
13380 KB |
Output is correct |
27 |
Correct |
178 ms |
23256 KB |
Output is correct |
28 |
Correct |
166 ms |
23364 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 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 |
9 ms |
1172 KB |
Output is correct |
37 |
Correct |
163 ms |
22052 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
7 ms |
1188 KB |
Output is correct |
41 |
Correct |
162 ms |
22048 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
3 ms |
716 KB |
Output is correct |
45 |
Correct |
78 ms |
13344 KB |
Output is correct |
46 |
Correct |
1 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 |
50 ms |
5856 KB |
Output is correct |
50 |
Correct |
162 ms |
23344 KB |
Output is correct |
51 |
Correct |
166 ms |
23236 KB |
Output is correct |
52 |
Correct |
172 ms |
23304 KB |
Output is correct |
53 |
Correct |
79 ms |
13388 KB |
Output is correct |
54 |
Correct |
71 ms |
13452 KB |
Output is correct |
55 |
Correct |
159 ms |
23304 KB |
Output is correct |
56 |
Correct |
176 ms |
23196 KB |
Output is correct |
57 |
Correct |
74 ms |
13348 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
3 ms |
732 KB |
Output is correct |
61 |
Correct |
76 ms |
13488 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
0 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Correct |
41 ms |
6180 KB |
Output is correct |
66 |
Correct |
72 ms |
13764 KB |
Output is correct |
67 |
Correct |
67 ms |
13828 KB |
Output is correct |
68 |
Correct |
69 ms |
13712 KB |
Output is correct |
69 |
Correct |
66 ms |
13764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
8 ms |
1156 KB |
Output is correct |
7 |
Correct |
162 ms |
22996 KB |
Output is correct |
8 |
Correct |
0 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 |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
170 ms |
22948 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
80 ms |
13352 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
42 ms |
6028 KB |
Output is correct |
21 |
Correct |
168 ms |
23200 KB |
Output is correct |
22 |
Correct |
162 ms |
23260 KB |
Output is correct |
23 |
Correct |
206 ms |
23308 KB |
Output is correct |
24 |
Correct |
164 ms |
23236 KB |
Output is correct |
25 |
Correct |
75 ms |
13292 KB |
Output is correct |
26 |
Correct |
78 ms |
13380 KB |
Output is correct |
27 |
Correct |
178 ms |
23256 KB |
Output is correct |
28 |
Correct |
166 ms |
23364 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 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 |
9 ms |
1172 KB |
Output is correct |
37 |
Correct |
163 ms |
22052 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
7 ms |
1188 KB |
Output is correct |
41 |
Correct |
162 ms |
22048 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
3 ms |
716 KB |
Output is correct |
45 |
Correct |
78 ms |
13344 KB |
Output is correct |
46 |
Correct |
1 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 |
50 ms |
5856 KB |
Output is correct |
50 |
Correct |
162 ms |
23344 KB |
Output is correct |
51 |
Correct |
166 ms |
23236 KB |
Output is correct |
52 |
Correct |
172 ms |
23304 KB |
Output is correct |
53 |
Correct |
79 ms |
13388 KB |
Output is correct |
54 |
Correct |
71 ms |
13452 KB |
Output is correct |
55 |
Correct |
159 ms |
23304 KB |
Output is correct |
56 |
Correct |
176 ms |
23196 KB |
Output is correct |
57 |
Correct |
74 ms |
13348 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
42 ms |
5732 KB |
Output is correct |
62 |
Correct |
162 ms |
22024 KB |
Output is correct |
63 |
Correct |
164 ms |
22052 KB |
Output is correct |
64 |
Correct |
171 ms |
21956 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
46 ms |
5780 KB |
Output is correct |
67 |
Correct |
165 ms |
22036 KB |
Output is correct |
68 |
Correct |
160 ms |
21956 KB |
Output is correct |
69 |
Correct |
177 ms |
22032 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
0 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
41 ms |
5700 KB |
Output is correct |
74 |
Correct |
161 ms |
22048 KB |
Output is correct |
75 |
Correct |
162 ms |
22044 KB |
Output is correct |
76 |
Correct |
159 ms |
21956 KB |
Output is correct |
77 |
Correct |
186 ms |
21956 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
0 ms |
204 KB |
Output is correct |
80 |
Correct |
3 ms |
732 KB |
Output is correct |
81 |
Correct |
76 ms |
13488 KB |
Output is correct |
82 |
Correct |
0 ms |
204 KB |
Output is correct |
83 |
Correct |
0 ms |
204 KB |
Output is correct |
84 |
Correct |
0 ms |
204 KB |
Output is correct |
85 |
Correct |
41 ms |
6180 KB |
Output is correct |
86 |
Correct |
72 ms |
13764 KB |
Output is correct |
87 |
Correct |
67 ms |
13828 KB |
Output is correct |
88 |
Correct |
69 ms |
13712 KB |
Output is correct |
89 |
Correct |
66 ms |
13764 KB |
Output is correct |
90 |
Correct |
0 ms |
204 KB |
Output is correct |
91 |
Correct |
0 ms |
204 KB |
Output is correct |
92 |
Correct |
3 ms |
844 KB |
Output is correct |
93 |
Correct |
79 ms |
13824 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 |
16 ms |
3720 KB |
Output is correct |
98 |
Correct |
66 ms |
14020 KB |
Output is correct |
99 |
Correct |
67 ms |
13952 KB |
Output is correct |
100 |
Correct |
66 ms |
14020 KB |
Output is correct |
101 |
Correct |
63 ms |
14020 KB |
Output is correct |
102 |
Correct |
68 ms |
14140 KB |
Output is correct |
103 |
Correct |
71 ms |
13952 KB |
Output is correct |
104 |
Correct |
65 ms |
14020 KB |
Output is correct |
105 |
Correct |
72 ms |
14012 KB |
Output is correct |