#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
int n, p[1005], isline[1005];
vi comp[1005];
bool vis[1005];
int fs(int x) {
if (p[x] == x) return x;
return p[x] = fs(p[x]);
}
int construct(vector<vector<int>> v) {
n = v.size();
vector<vi> ans = vector<vi>(n, vi(n, 0));
vector<vi> check = vector<vi>(n, vi(n, 0));
memset(isline, -1, sizeof isline);
FOR(i, 0, n-1) p[i] = i;
FOR(i, 0, n-1) FOR(j, 0, n-1) if (v[i][j]) p[fs(i)] = fs(j);
FOR(i, 0, n-1) comp[fs(i)].pb(i);
FOR(it, 0, n-1) {
vi line, cyc;
for (auto i:comp[it]) {
bool ok = 0;
for (auto j:comp[it]) if (i != j and v[i][j] == 1) ok = 1;
(ok ? line : cyc).pb(i);
if (ok) isline[i] = i;
}
for (auto i:line) {
if (vis[i]) continue;
vis[i] = 1;
cyc.pb(i);
int pre = i;
FOR(j, 0, n-1) if (i != j and v[i][j] == 1 and isline[j]) {
ans[pre][j] = ans[j][pre] = 1;
pre = j; vis[j] = 1; isline[j] = i;
}
}
if (cyc.size() == 2) return 0;
FOR(i, 1, cyc.size()-1) ans[cyc[i-1]][cyc[i]] = ans[cyc[i]][cyc[i-1]] = 1;
if (cyc.size() > 1) ans[cyc[0]][cyc.back()] = ans[cyc.back()][cyc[0]] = 1;
for (auto i:comp[it]) for (auto j:comp[it]) {
if (isline[i] == -1 or isline[j] == -1 or isline[i] != isline[j]) check[i][j] = 2;
else check[i][j] = 1;
if (i == j) check[i][j] = 1;
}
}
if (check != v) return 0;
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
262 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
262 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
127 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6852 KB |
Output is correct |
21 |
Correct |
242 ms |
26060 KB |
Output is correct |
22 |
Correct |
236 ms |
26104 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
235 ms |
26064 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16116 KB |
Output is correct |
27 |
Correct |
261 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
232 ms |
26108 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
265 ms |
26100 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
125 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
59 ms |
6776 KB |
Output is correct |
22 |
Correct |
243 ms |
26104 KB |
Output is correct |
23 |
Correct |
236 ms |
26232 KB |
Output is correct |
24 |
Correct |
262 ms |
26104 KB |
Output is correct |
25 |
Correct |
95 ms |
16120 KB |
Output is correct |
26 |
Correct |
101 ms |
16124 KB |
Output is correct |
27 |
Correct |
236 ms |
26100 KB |
Output is correct |
28 |
Correct |
263 ms |
26104 KB |
Output is correct |
29 |
Correct |
97 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
59 ms |
6904 KB |
Output is correct |
5 |
Correct |
240 ms |
26064 KB |
Output is correct |
6 |
Correct |
246 ms |
26104 KB |
Output is correct |
7 |
Correct |
264 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
60 ms |
6904 KB |
Output is correct |
10 |
Correct |
238 ms |
26104 KB |
Output is correct |
11 |
Correct |
237 ms |
26104 KB |
Output is correct |
12 |
Correct |
259 ms |
26104 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
60 ms |
7020 KB |
Output is correct |
17 |
Correct |
239 ms |
26232 KB |
Output is correct |
18 |
Correct |
241 ms |
26104 KB |
Output is correct |
19 |
Correct |
236 ms |
26232 KB |
Output is correct |
20 |
Correct |
235 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
262 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
127 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6852 KB |
Output is correct |
21 |
Correct |
242 ms |
26060 KB |
Output is correct |
22 |
Correct |
236 ms |
26104 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
235 ms |
26064 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16116 KB |
Output is correct |
27 |
Correct |
261 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
232 ms |
26108 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
265 ms |
26100 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
125 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
59 ms |
6776 KB |
Output is correct |
50 |
Correct |
243 ms |
26104 KB |
Output is correct |
51 |
Correct |
236 ms |
26232 KB |
Output is correct |
52 |
Correct |
262 ms |
26104 KB |
Output is correct |
53 |
Correct |
95 ms |
16120 KB |
Output is correct |
54 |
Correct |
101 ms |
16124 KB |
Output is correct |
55 |
Correct |
236 ms |
26100 KB |
Output is correct |
56 |
Correct |
263 ms |
26104 KB |
Output is correct |
57 |
Correct |
97 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
7 ms |
1024 KB |
Output is correct |
61 |
Correct |
125 ms |
16124 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
59 ms |
6904 KB |
Output is correct |
66 |
Correct |
107 ms |
16116 KB |
Output is correct |
67 |
Correct |
100 ms |
16120 KB |
Output is correct |
68 |
Correct |
99 ms |
16120 KB |
Output is correct |
69 |
Correct |
97 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
262 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
127 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6852 KB |
Output is correct |
21 |
Correct |
242 ms |
26060 KB |
Output is correct |
22 |
Correct |
236 ms |
26104 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
235 ms |
26064 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16116 KB |
Output is correct |
27 |
Correct |
261 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
232 ms |
26108 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
265 ms |
26100 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
125 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
59 ms |
6776 KB |
Output is correct |
50 |
Correct |
243 ms |
26104 KB |
Output is correct |
51 |
Correct |
236 ms |
26232 KB |
Output is correct |
52 |
Correct |
262 ms |
26104 KB |
Output is correct |
53 |
Correct |
95 ms |
16120 KB |
Output is correct |
54 |
Correct |
101 ms |
16124 KB |
Output is correct |
55 |
Correct |
236 ms |
26100 KB |
Output is correct |
56 |
Correct |
263 ms |
26104 KB |
Output is correct |
57 |
Correct |
97 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
384 KB |
Output is correct |
60 |
Correct |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
59 ms |
6904 KB |
Output is correct |
62 |
Correct |
240 ms |
26064 KB |
Output is correct |
63 |
Correct |
246 ms |
26104 KB |
Output is correct |
64 |
Correct |
264 ms |
26104 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
60 ms |
6904 KB |
Output is correct |
67 |
Correct |
238 ms |
26104 KB |
Output is correct |
68 |
Correct |
237 ms |
26104 KB |
Output is correct |
69 |
Correct |
259 ms |
26104 KB |
Output is correct |
70 |
Correct |
0 ms |
384 KB |
Output is correct |
71 |
Correct |
0 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
60 ms |
7020 KB |
Output is correct |
74 |
Correct |
239 ms |
26232 KB |
Output is correct |
75 |
Correct |
241 ms |
26104 KB |
Output is correct |
76 |
Correct |
236 ms |
26232 KB |
Output is correct |
77 |
Correct |
235 ms |
26104 KB |
Output is correct |
78 |
Correct |
1 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
7 ms |
1024 KB |
Output is correct |
81 |
Correct |
125 ms |
16124 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
59 ms |
6904 KB |
Output is correct |
86 |
Correct |
107 ms |
16116 KB |
Output is correct |
87 |
Correct |
100 ms |
16120 KB |
Output is correct |
88 |
Correct |
99 ms |
16120 KB |
Output is correct |
89 |
Correct |
97 ms |
16120 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
0 ms |
384 KB |
Output is correct |
92 |
Correct |
7 ms |
1024 KB |
Output is correct |
93 |
Correct |
139 ms |
16120 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
1 ms |
384 KB |
Output is correct |
96 |
Correct |
1 ms |
384 KB |
Output is correct |
97 |
Correct |
24 ms |
4352 KB |
Output is correct |
98 |
Correct |
102 ms |
16120 KB |
Output is correct |
99 |
Correct |
100 ms |
16120 KB |
Output is correct |
100 |
Correct |
98 ms |
16116 KB |
Output is correct |
101 |
Correct |
99 ms |
16116 KB |
Output is correct |
102 |
Correct |
120 ms |
16120 KB |
Output is correct |
103 |
Correct |
121 ms |
16120 KB |
Output is correct |
104 |
Correct |
123 ms |
16120 KB |
Output is correct |
105 |
Correct |
132 ms |
16248 KB |
Output is correct |