#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "supertrees.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back
const int maxN = 1000;
int parent[maxN][4], sz[maxN][4];
int find_parent(int a, int con) {
if (parent[a][con] == a) return a;
else return parent[a][con] = find_parent(parent[a][con], con);
}
void merge(int a, int b, int con) {
a = find_parent(a, con);
b = find_parent(b, con);
if (a == b) return;
if (sz[a][con] < sz[b][con]) swap(a, b);
parent[b][con] = a;
sz[a][con] += sz[b][con];
}
bool same_set(int a, int b, int con) {
a = find_parent(a, con);
b = find_parent(b, con);
return a == b;
}
void make_set(int n) {
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= 3; ++j) {
parent[i][j] = i;
sz[i][j] = 1;
}
}
}
int construct(vvi p) {
int n = p.size();
vvi A(n, vi(n, 0));
make_set(n);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
//HOLY HOLY FUCK, for p[i][j] = 3 answer doesn't exist, how did I miss this?
//Also hint: only 4 points for solving p[i][j] = 3
if (p[i][j] == 3) return 0;
if (p[i][j] == 1) merge(i, j, p[i][j]);
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (!p[i][j] && same_set(i, j, 1)) return 0;
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int a = find_parent(i, 1), b = find_parent(j, 1);
if (p[i][j] > 1) {
if (a == b) return 0;
merge(a, b, p[i][j]);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int a = find_parent(i, 1), b = find_parent(j, 1);
if (!p[i][j] && (same_set(i, j, 2) || same_set(a, b, 2) || same_set(i, j, 3) || same_set(a, b, 3))) return 0;
}
}
// for (int i = 0; i < n; ++i) {
// for (int j = i + 1; j < n; ++j) {
// int cnt = 0;
// int a = find_parent(i, 1), b = find_parent(j, 1);
// for (int k = 1; k <= 3; ++k) {
// cnt += same_set(a, b, k);
// }
// if (cnt > 1) {
// cout << "LOL: " << i << " " << j << " " << cnt << END;
// return 0;
// }
// }
// }
vector<vvi> comps(4, vvi(n));
for (int i = 0; i < n; ++i) {
int c = find_parent(i, 1);
int a = find_parent(c, 2), b = find_parent(c, 3);
if (sz[a][2] > 1 && sz[b][3] > 1) return 0;
if (sz[a][2] == 2) return 0;
if (sz[b][3] > 1 && sz[b][3] < 4) return 0;
comps[1][c].pb(i);
if (c == i)
comps[2][a].pb(i);
if (c == i)
comps[3][b].pb(i);
}
for (int i = 0; i < n; ++i) {
if ((int)comps[1][i].size() <= 1) continue;
for (int j = 1; j < (int)comps[1][i].size(); ++j) {
int a = comps[1][i][j], b = comps[1][i][j - 1];
if (a == b) {
cout << "FUCK";
}
A[a][b] = A[b][a] = 1;
}
}
for (int i = 0; i < n; ++i) {
if ((int)comps[2][i].size() <= 1) continue;
for (int j = 1; j < (int)comps[2][i].size(); ++j) {
int a = comps[2][i][j], b = comps[2][i][j - 1];
if (a == b) {
cout << "DAMN";
}
A[a][b] = A[b][a] = 1;
}
int a = comps[2][i][0], b = comps[2][i].back();
A[a][b] = A[b][a] = 1;
if (a == b) {
cout << "DAMN_ME";
}
}
for (int i = 0; i < n; ++i) {
if ((int)comps[3][i].size() <= 1) continue;
for (int j = 1; j < (int)comps[3][i].size(); ++j) {
int a = comps[3][i][j], b = comps[3][i][j - 1];
if (a == b) {
cout << "WOW";
}
A[a][b] = A[b][a] = 1;
}
int a = comps[3][i][0], b = comps[3][i].back(), c = comps[3][i][1];
if (b == c) {
cout << "WOW_ME";
}
A[a][b] = A[b][a] = 1;
A[b][c] = A[c][b] = 1;
}
build(A);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 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 |
1260 KB |
Output is correct |
7 |
Correct |
253 ms |
22252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 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 |
1260 KB |
Output is correct |
7 |
Correct |
253 ms |
22252 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 |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22400 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
115 ms |
12140 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
267 ms |
22252 KB |
Output is correct |
22 |
Correct |
262 ms |
22252 KB |
Output is correct |
23 |
Correct |
274 ms |
22252 KB |
Output is correct |
24 |
Correct |
254 ms |
22372 KB |
Output is correct |
25 |
Correct |
111 ms |
12140 KB |
Output is correct |
26 |
Correct |
105 ms |
12168 KB |
Output is correct |
27 |
Correct |
331 ms |
22252 KB |
Output is correct |
28 |
Correct |
256 ms |
22504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
14 ms |
1260 KB |
Output is correct |
9 |
Correct |
252 ms |
22252 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
13 ms |
1260 KB |
Output is correct |
13 |
Correct |
247 ms |
22252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
121 ms |
12140 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
64 ms |
5868 KB |
Output is correct |
22 |
Correct |
261 ms |
22380 KB |
Output is correct |
23 |
Correct |
258 ms |
22272 KB |
Output is correct |
24 |
Correct |
267 ms |
22380 KB |
Output is correct |
25 |
Correct |
117 ms |
12396 KB |
Output is correct |
26 |
Correct |
110 ms |
12140 KB |
Output is correct |
27 |
Correct |
256 ms |
22380 KB |
Output is correct |
28 |
Correct |
266 ms |
22252 KB |
Output is correct |
29 |
Correct |
120 ms |
12532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
78 ms |
5936 KB |
Output is correct |
5 |
Correct |
265 ms |
22404 KB |
Output is correct |
6 |
Correct |
260 ms |
22508 KB |
Output is correct |
7 |
Correct |
282 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
65 ms |
5868 KB |
Output is correct |
10 |
Correct |
263 ms |
22380 KB |
Output is correct |
11 |
Correct |
259 ms |
22252 KB |
Output is correct |
12 |
Correct |
279 ms |
22252 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
65 ms |
5868 KB |
Output is correct |
17 |
Correct |
264 ms |
22244 KB |
Output is correct |
18 |
Correct |
267 ms |
22252 KB |
Output is correct |
19 |
Correct |
267 ms |
22380 KB |
Output is correct |
20 |
Correct |
291 ms |
22284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 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 |
1260 KB |
Output is correct |
7 |
Correct |
253 ms |
22252 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 |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22400 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
115 ms |
12140 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
267 ms |
22252 KB |
Output is correct |
22 |
Correct |
262 ms |
22252 KB |
Output is correct |
23 |
Correct |
274 ms |
22252 KB |
Output is correct |
24 |
Correct |
254 ms |
22372 KB |
Output is correct |
25 |
Correct |
111 ms |
12140 KB |
Output is correct |
26 |
Correct |
105 ms |
12168 KB |
Output is correct |
27 |
Correct |
331 ms |
22252 KB |
Output is correct |
28 |
Correct |
256 ms |
22504 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 |
0 ms |
364 KB |
Output is correct |
36 |
Correct |
14 ms |
1260 KB |
Output is correct |
37 |
Correct |
252 ms |
22252 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
13 ms |
1260 KB |
Output is correct |
41 |
Correct |
247 ms |
22252 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
121 ms |
12140 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
0 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
5868 KB |
Output is correct |
50 |
Correct |
261 ms |
22380 KB |
Output is correct |
51 |
Correct |
258 ms |
22272 KB |
Output is correct |
52 |
Correct |
267 ms |
22380 KB |
Output is correct |
53 |
Correct |
117 ms |
12396 KB |
Output is correct |
54 |
Correct |
110 ms |
12140 KB |
Output is correct |
55 |
Correct |
256 ms |
22380 KB |
Output is correct |
56 |
Correct |
266 ms |
22252 KB |
Output is correct |
57 |
Correct |
120 ms |
12532 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 |
852 KB |
Output is correct |
61 |
Correct |
114 ms |
12140 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 |
66 ms |
5868 KB |
Output is correct |
66 |
Correct |
111 ms |
12140 KB |
Output is correct |
67 |
Correct |
107 ms |
12268 KB |
Output is correct |
68 |
Correct |
117 ms |
12140 KB |
Output is correct |
69 |
Correct |
119 ms |
12268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 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 |
1260 KB |
Output is correct |
7 |
Correct |
253 ms |
22252 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 |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22400 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
115 ms |
12140 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
267 ms |
22252 KB |
Output is correct |
22 |
Correct |
262 ms |
22252 KB |
Output is correct |
23 |
Correct |
274 ms |
22252 KB |
Output is correct |
24 |
Correct |
254 ms |
22372 KB |
Output is correct |
25 |
Correct |
111 ms |
12140 KB |
Output is correct |
26 |
Correct |
105 ms |
12168 KB |
Output is correct |
27 |
Correct |
331 ms |
22252 KB |
Output is correct |
28 |
Correct |
256 ms |
22504 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 |
0 ms |
364 KB |
Output is correct |
36 |
Correct |
14 ms |
1260 KB |
Output is correct |
37 |
Correct |
252 ms |
22252 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
13 ms |
1260 KB |
Output is correct |
41 |
Correct |
247 ms |
22252 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
852 KB |
Output is correct |
45 |
Correct |
121 ms |
12140 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
0 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
5868 KB |
Output is correct |
50 |
Correct |
261 ms |
22380 KB |
Output is correct |
51 |
Correct |
258 ms |
22272 KB |
Output is correct |
52 |
Correct |
267 ms |
22380 KB |
Output is correct |
53 |
Correct |
117 ms |
12396 KB |
Output is correct |
54 |
Correct |
110 ms |
12140 KB |
Output is correct |
55 |
Correct |
256 ms |
22380 KB |
Output is correct |
56 |
Correct |
266 ms |
22252 KB |
Output is correct |
57 |
Correct |
120 ms |
12532 KB |
Output is correct |
58 |
Correct |
1 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 |
78 ms |
5936 KB |
Output is correct |
62 |
Correct |
265 ms |
22404 KB |
Output is correct |
63 |
Correct |
260 ms |
22508 KB |
Output is correct |
64 |
Correct |
282 ms |
22252 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
65 ms |
5868 KB |
Output is correct |
67 |
Correct |
263 ms |
22380 KB |
Output is correct |
68 |
Correct |
259 ms |
22252 KB |
Output is correct |
69 |
Correct |
279 ms |
22252 KB |
Output is correct |
70 |
Correct |
1 ms |
492 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
65 ms |
5868 KB |
Output is correct |
74 |
Correct |
264 ms |
22244 KB |
Output is correct |
75 |
Correct |
267 ms |
22252 KB |
Output is correct |
76 |
Correct |
267 ms |
22380 KB |
Output is correct |
77 |
Correct |
291 ms |
22284 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 |
852 KB |
Output is correct |
81 |
Correct |
114 ms |
12140 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 |
66 ms |
5868 KB |
Output is correct |
86 |
Correct |
111 ms |
12140 KB |
Output is correct |
87 |
Correct |
107 ms |
12268 KB |
Output is correct |
88 |
Correct |
117 ms |
12140 KB |
Output is correct |
89 |
Correct |
119 ms |
12268 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 |
852 KB |
Output is correct |
93 |
Correct |
107 ms |
12140 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 |
26 ms |
3308 KB |
Output is correct |
98 |
Correct |
104 ms |
12140 KB |
Output is correct |
99 |
Correct |
105 ms |
12140 KB |
Output is correct |
100 |
Correct |
105 ms |
12140 KB |
Output is correct |
101 |
Correct |
104 ms |
12140 KB |
Output is correct |
102 |
Correct |
102 ms |
12140 KB |
Output is correct |
103 |
Correct |
102 ms |
14188 KB |
Output is correct |
104 |
Correct |
106 ms |
14164 KB |
Output is correct |
105 |
Correct |
111 ms |
14188 KB |
Output is correct |