# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636386 | 2022-08-29T03:32:03 Z | ghostwriter | Connecting Supertrees (IOI20_supertrees) | C++14 | 248 ms | 30492 KB |
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const int MAXN = 1005; int N, P[MAXN][MAXN], adj[MAXN][MAXN], p1[MAXN], s[MAXN], c[MAXN], cnt = 0; bitset<MAXN> d[MAXN]; vi nodes, cc[MAXN]; int getp(int i) { return i == p1[i]? i : p1[i] = getp(p1[i]); } bool join(int x, int y) { x = getp(x); y = getp(y); if (x == y) return 0; if (s[y] > s[x]) swap(x, y); p1[y] = x; s[x] += s[y]; return 1; } void dfs(int u) { c[u] = 1; nodes.pb(u); FOR(v, 0, N - 1) { if (!P[u][v] || c[v]) continue; dfs(v); } } void dfs1(int u) { c[u] = 1; cc[cnt].pb(u); FOR(v, 0, N - 1) { if (P[u][v] != 1 || c[v]) continue; dfs1(v); } } void dfs2(int u) { c[u] = 1; nodes.pb(u); FOR(v, 1, cnt) { if (!adj[u][v] || c[v]) continue; dfs2(v); } } int construct(std::vector<std::vector<int>> p) { int n = p.size(); N = n; std::vector<std::vector<int>> ans; for (int i = 0; i < n; i++) { std::vector<int> row(n, 0); ans.push_back(row); } FOR(i, 0, n - 1) FOR(j, 0, n - 1) P[i][j] = p[i][j]; int sub6 = 0; FOR(i, 0, n - 1) FOR(j, 0, n - 1) if (p[i][j] == 3) sub6 = 1; if (sub6) return 0; bool sub1 = 1; EACH(i, p) EACH(j, i) if (j != 1) sub1 = 0; if (sub1) { FOR(i, 0, n - 2) ans[i][i + 1] = ans[i + 1][i] = 1; build(ans); return 1; } bool connectivity = 1; FOR(i, 0, n - 1) FOR(j, 0, n - 1) d[i][j] = (p[i][j]? 1 : 0); FOR(i, 0, n - 1) FOR(j, 0, n - 1) if (!d[i][j]) { bitset<MAXN> cur = d[i] & d[j]; int cnt = cur.count(); if (cnt) connectivity = 0; } if (!connectivity) return 0; bool sub2 = 1; EACH(i, p) EACH(j, i) if (j != 0 && j != 1) sub2 = 0; if (sub2) { FOR(i, 0, n - 1) { p1[i] = i; s[i] = 1; } FOR(i, 0, n - 1) FOR(j, 0, n - 1) { if (!p[i][j] || !join(i, j)) continue; ans[i][j] = ans[j][i] = 1; } build(ans); return 1; } bool sub3 = 1; FOR(i, 0, n - 1) FOR(j, 0, n - 1) if (i != j && p[i][j] != 0 && p[i][j] != 2) sub3 = 0; if (sub3) { FOR(i, 0, n - 1) { if (c[i]) continue; nodes.clear(); dfs(i); if (sz(nodes) == 1) continue; if (sz(nodes) == 2) return 0; FOR(j, 0, sz(nodes) - 2) ans[nodes[j]][nodes[j + 1]] = ans[nodes[j + 1]][nodes[j]] = 1; ans[nodes[0]][nodes.back()] = ans[nodes.back()][nodes[0]] = 1; } build(ans); return 1; } FOR(i, 0, n - 1) { if (c[i]) continue; ++cnt; dfs1(i); FOR(j, 0, sz(cc[cnt]) - 2) ans[cc[cnt][j]][cc[cnt][j + 1]] = ans[cc[cnt][j + 1]][cc[cnt][j]] = 1; } FOR(i, 1, cnt) FOR(j, 1, cnt) { if (i == j) continue; bool ok = 0; EACH(x, cc[i]) EACH(y, cc[j]) if (p[x][y] == 2) ok = 1; if (!ok) continue; EACH(x, cc[i]) EACH(y, cc[j]) if (p[x][y] != 2) ok = 0; if (!ok) return 0; adj[i][j] = 1; } memset(c, 0, sizeof c); FOR(i, 1, cnt) { if (c[i]) continue; nodes.clear(); dfs2(i); if (sz(nodes) == 1) continue; if (sz(nodes) == 2) return 0; FOR(j, 0, sz(nodes) - 2) { int u = nodes[j], v = nodes[j + 1]; ans[cc[u][0]][cc[v][0]] = ans[cc[v][0]][cc[u][0]] = 1; } int u = nodes.front(), v = nodes.back(); ans[cc[u][0]][cc[v][0]] = ans[cc[v][0]][cc[u][0]] = 1; } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2004 KB | Output is correct |
7 | Correct | 174 ms | 25908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2004 KB | Output is correct |
7 | Correct | 174 ms | 25908 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 10 ms | 2004 KB | Output is correct |
13 | Correct | 226 ms | 26160 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1620 KB | Output is correct |
17 | Correct | 110 ms | 16164 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 59 ms | 7748 KB | Output is correct |
21 | Correct | 223 ms | 26164 KB | Output is correct |
22 | Correct | 225 ms | 26280 KB | Output is correct |
23 | Correct | 229 ms | 26152 KB | Output is correct |
24 | Correct | 230 ms | 26152 KB | Output is correct |
25 | Correct | 121 ms | 16180 KB | Output is correct |
26 | Correct | 134 ms | 16292 KB | Output is correct |
27 | Correct | 211 ms | 26116 KB | Output is correct |
28 | Correct | 248 ms | 26160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 10 ms | 2060 KB | Output is correct |
9 | Correct | 225 ms | 26152 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 8 ms | 2004 KB | Output is correct |
13 | Correct | 173 ms | 26132 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1620 KB | Output is correct |
17 | Correct | 109 ms | 16180 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 0 ms | 340 KB | Output is correct |
21 | Correct | 57 ms | 7792 KB | Output is correct |
22 | Correct | 222 ms | 26148 KB | Output is correct |
23 | Correct | 223 ms | 26220 KB | Output is correct |
24 | Correct | 212 ms | 26152 KB | Output is correct |
25 | Correct | 122 ms | 16308 KB | Output is correct |
26 | Correct | 123 ms | 16168 KB | Output is correct |
27 | Correct | 229 ms | 26068 KB | Output is correct |
28 | Correct | 210 ms | 26176 KB | Output is correct |
29 | Correct | 127 ms | 16204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 60 ms | 7836 KB | Output is correct |
5 | Correct | 222 ms | 26060 KB | Output is correct |
6 | Correct | 228 ms | 26056 KB | Output is correct |
7 | Correct | 215 ms | 26140 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 61 ms | 7852 KB | Output is correct |
10 | Correct | 221 ms | 26108 KB | Output is correct |
11 | Correct | 232 ms | 26108 KB | Output is correct |
12 | Correct | 209 ms | 26192 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 59 ms | 9848 KB | Output is correct |
17 | Correct | 224 ms | 28112 KB | Output is correct |
18 | Correct | 226 ms | 30248 KB | Output is correct |
19 | Correct | 234 ms | 30492 KB | Output is correct |
20 | Correct | 225 ms | 28364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2004 KB | Output is correct |
7 | Correct | 174 ms | 25908 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 10 ms | 2004 KB | Output is correct |
13 | Correct | 226 ms | 26160 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1620 KB | Output is correct |
17 | Correct | 110 ms | 16164 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 59 ms | 7748 KB | Output is correct |
21 | Correct | 223 ms | 26164 KB | Output is correct |
22 | Correct | 225 ms | 26280 KB | Output is correct |
23 | Correct | 229 ms | 26152 KB | Output is correct |
24 | Correct | 230 ms | 26152 KB | Output is correct |
25 | Correct | 121 ms | 16180 KB | Output is correct |
26 | Correct | 134 ms | 16292 KB | Output is correct |
27 | Correct | 211 ms | 26116 KB | Output is correct |
28 | Correct | 248 ms | 26160 KB | Output is correct |
29 | Correct | 0 ms | 340 KB | Output is correct |
30 | Correct | 0 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 340 KB | Output is correct |
32 | Correct | 0 ms | 340 KB | Output is correct |
33 | Correct | 0 ms | 340 KB | Output is correct |
34 | Correct | 0 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 10 ms | 2060 KB | Output is correct |
37 | Correct | 225 ms | 26152 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
40 | Correct | 8 ms | 2004 KB | Output is correct |
41 | Correct | 173 ms | 26132 KB | Output is correct |
42 | Correct | 0 ms | 340 KB | Output is correct |
43 | Correct | 1 ms | 340 KB | Output is correct |
44 | Correct | 5 ms | 1620 KB | Output is correct |
45 | Correct | 109 ms | 16180 KB | Output is correct |
46 | Correct | 0 ms | 340 KB | Output is correct |
47 | Correct | 0 ms | 344 KB | Output is correct |
48 | Correct | 0 ms | 340 KB | Output is correct |
49 | Correct | 57 ms | 7792 KB | Output is correct |
50 | Correct | 222 ms | 26148 KB | Output is correct |
51 | Correct | 223 ms | 26220 KB | Output is correct |
52 | Correct | 212 ms | 26152 KB | Output is correct |
53 | Correct | 122 ms | 16308 KB | Output is correct |
54 | Correct | 123 ms | 16168 KB | Output is correct |
55 | Correct | 229 ms | 26068 KB | Output is correct |
56 | Correct | 210 ms | 26176 KB | Output is correct |
57 | Correct | 127 ms | 16204 KB | Output is correct |
58 | Correct | 0 ms | 340 KB | Output is correct |
59 | Correct | 0 ms | 340 KB | Output is correct |
60 | Correct | 4 ms | 1620 KB | Output is correct |
61 | Correct | 99 ms | 16176 KB | Output is correct |
62 | Correct | 0 ms | 340 KB | Output is correct |
63 | Correct | 0 ms | 340 KB | Output is correct |
64 | Correct | 0 ms | 340 KB | Output is correct |
65 | Correct | 60 ms | 9808 KB | Output is correct |
66 | Correct | 119 ms | 18208 KB | Output is correct |
67 | Correct | 121 ms | 18072 KB | Output is correct |
68 | Correct | 125 ms | 18128 KB | Output is correct |
69 | Correct | 127 ms | 18380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2004 KB | Output is correct |
7 | Correct | 174 ms | 25908 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 10 ms | 2004 KB | Output is correct |
13 | Correct | 226 ms | 26160 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1620 KB | Output is correct |
17 | Correct | 110 ms | 16164 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 59 ms | 7748 KB | Output is correct |
21 | Correct | 223 ms | 26164 KB | Output is correct |
22 | Correct | 225 ms | 26280 KB | Output is correct |
23 | Correct | 229 ms | 26152 KB | Output is correct |
24 | Correct | 230 ms | 26152 KB | Output is correct |
25 | Correct | 121 ms | 16180 KB | Output is correct |
26 | Correct | 134 ms | 16292 KB | Output is correct |
27 | Correct | 211 ms | 26116 KB | Output is correct |
28 | Correct | 248 ms | 26160 KB | Output is correct |
29 | Correct | 0 ms | 340 KB | Output is correct |
30 | Correct | 0 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 340 KB | Output is correct |
32 | Correct | 0 ms | 340 KB | Output is correct |
33 | Correct | 0 ms | 340 KB | Output is correct |
34 | Correct | 0 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 10 ms | 2060 KB | Output is correct |
37 | Correct | 225 ms | 26152 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
40 | Correct | 8 ms | 2004 KB | Output is correct |
41 | Correct | 173 ms | 26132 KB | Output is correct |
42 | Correct | 0 ms | 340 KB | Output is correct |
43 | Correct | 1 ms | 340 KB | Output is correct |
44 | Correct | 5 ms | 1620 KB | Output is correct |
45 | Correct | 109 ms | 16180 KB | Output is correct |
46 | Correct | 0 ms | 340 KB | Output is correct |
47 | Correct | 0 ms | 344 KB | Output is correct |
48 | Correct | 0 ms | 340 KB | Output is correct |
49 | Correct | 57 ms | 7792 KB | Output is correct |
50 | Correct | 222 ms | 26148 KB | Output is correct |
51 | Correct | 223 ms | 26220 KB | Output is correct |
52 | Correct | 212 ms | 26152 KB | Output is correct |
53 | Correct | 122 ms | 16308 KB | Output is correct |
54 | Correct | 123 ms | 16168 KB | Output is correct |
55 | Correct | 229 ms | 26068 KB | Output is correct |
56 | Correct | 210 ms | 26176 KB | Output is correct |
57 | Correct | 127 ms | 16204 KB | Output is correct |
58 | Correct | 1 ms | 340 KB | Output is correct |
59 | Correct | 0 ms | 340 KB | Output is correct |
60 | Correct | 0 ms | 340 KB | Output is correct |
61 | Correct | 60 ms | 7836 KB | Output is correct |
62 | Correct | 222 ms | 26060 KB | Output is correct |
63 | Correct | 228 ms | 26056 KB | Output is correct |
64 | Correct | 215 ms | 26140 KB | Output is correct |
65 | Correct | 0 ms | 340 KB | Output is correct |
66 | Correct | 61 ms | 7852 KB | Output is correct |
67 | Correct | 221 ms | 26108 KB | Output is correct |
68 | Correct | 232 ms | 26108 KB | Output is correct |
69 | Correct | 209 ms | 26192 KB | Output is correct |
70 | Correct | 0 ms | 340 KB | Output is correct |
71 | Correct | 0 ms | 340 KB | Output is correct |
72 | Correct | 1 ms | 336 KB | Output is correct |
73 | Correct | 59 ms | 9848 KB | Output is correct |
74 | Correct | 224 ms | 28112 KB | Output is correct |
75 | Correct | 226 ms | 30248 KB | Output is correct |
76 | Correct | 234 ms | 30492 KB | Output is correct |
77 | Correct | 225 ms | 28364 KB | Output is correct |
78 | Correct | 0 ms | 340 KB | Output is correct |
79 | Correct | 0 ms | 340 KB | Output is correct |
80 | Correct | 4 ms | 1620 KB | Output is correct |
81 | Correct | 99 ms | 16176 KB | Output is correct |
82 | Correct | 0 ms | 340 KB | Output is correct |
83 | Correct | 0 ms | 340 KB | Output is correct |
84 | Correct | 0 ms | 340 KB | Output is correct |
85 | Correct | 60 ms | 9808 KB | Output is correct |
86 | Correct | 119 ms | 18208 KB | Output is correct |
87 | Correct | 121 ms | 18072 KB | Output is correct |
88 | Correct | 125 ms | 18128 KB | Output is correct |
89 | Correct | 127 ms | 18380 KB | Output is correct |
90 | Correct | 0 ms | 340 KB | Output is correct |
91 | Correct | 0 ms | 340 KB | Output is correct |
92 | Correct | 4 ms | 1596 KB | Output is correct |
93 | Correct | 74 ms | 18004 KB | Output is correct |
94 | Correct | 0 ms | 340 KB | Output is correct |
95 | Correct | 0 ms | 340 KB | Output is correct |
96 | Correct | 1 ms | 340 KB | Output is correct |
97 | Correct | 17 ms | 5716 KB | Output is correct |
98 | Correct | 72 ms | 18072 KB | Output is correct |
99 | Correct | 68 ms | 18072 KB | Output is correct |
100 | Correct | 66 ms | 17956 KB | Output is correct |
101 | Correct | 69 ms | 18076 KB | Output is correct |
102 | Correct | 68 ms | 18072 KB | Output is correct |
103 | Correct | 68 ms | 18076 KB | Output is correct |
104 | Correct | 67 ms | 18072 KB | Output is correct |
105 | Correct | 71 ms | 18004 KB | Output is correct |