# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043789 |
2024-08-04T17:36:08 Z |
abczz |
Meetings (JOI19_meetings) |
C++17 |
|
469 ms |
1396 KB |
#include "meetings.h"
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <array>
#define ll long long
using namespace std;
bool C[2000], B[2000];
ll sz[2000], tot, node_cnt;
unordered_map <ll, ll> adj[2000];
void add_edge(ll u, ll v) {
node_cnt += (ll)(B[u] ^ 1) + (ll)(B[v] ^ 1);
B[u] = B[v] = 1;
adj[u][v] = adj[v][u] = 1;
}
void del_edge(ll u, ll v) {
adj[u].erase(v);
adj[v].erase(u);
}
void ins(ll u, ll v, ll x) {
del_edge(u, v);
add_edge(u, x);
add_edge(x, v);
}
ll find_centroid(ll u, ll p, ll w) {
sz[u] = 1;
ll mx = -1, res = -1;
for (auto [v, x] : adj[u]) {
if (!C[v] && v != p) {
res = max(res, find_centroid(v, u, w));
sz[u] += sz[v];
mx = max(mx, sz[v]);
}
}
mx = max(mx, w-sz[u]);
if (mx <= w/2) return u;
else return res;
}
void dfs_sz(ll u, ll p) {
sz[u] = 1;
for (auto [v, x] : adj[u]) {
if (!C[v] && v != p) {
dfs_sz(v, u);
sz[u] += sz[v];
}
}
}
void solve(ll u, ll w) {
ll c = find_centroid(u, -1, w);
dfs_sz(c, -1);
C[c] = 1;
vector <array<ll, 2>> V;
for (auto [v, x] : adj[c]) {
if (!C[v]) {
V.push_back({sz[v], v});
}
}
sort(V.begin(), V.end());
while (!V.empty()) {
if (V.size() > 1) {
auto [x, a] = V.back();
V.pop_back();
auto [y, b] = V.back();
V.pop_back();
ll z = Query(a, b, tot);
if (z == a) {
solve(a, sz[a]);
return;
}
else if (z == b) {
solve(b, sz[b]);
return;
}
else if (z == tot) {
ll tmp = Query(a, tot, c);
if (tmp == tot) ins(a, c, tot);
else ins(b, c, tot);
return;
}
else if (z != c) {
ll tmp = Query(a, tot, c);
if (tmp == z) {
ins(a, c, z);
add_edge(z, tot);
}
else {
ins(b, c, z);
add_edge(z, tot);
}
return;
}
}
else {
auto [x, a] = V.back();
V.pop_back();
ll z = Query(a, c, tot);
if (z == tot) ins(a, c, tot);
else if (z == a) solve(a, sz[a]);
else if (z != c) {
ins(a, c, z);
add_edge(z, tot);
}
else add_edge(c, tot);
return;
}
}
add_edge(c, tot);
}
void Solve(int N) {
for (int i=0; i<N; ++i) {
B[i] = 0;
adj[i].clear();
}
ll x = Query(0, 1, 2);
for (int i=0; i<=2; ++i) {
if (i == x) continue;
add_edge(i, x);
}
for (int i=3; i<N; ++i) {
if (B[i]) continue;
tot = i;
for (int j=0; j<N; ++j) {
C[j] = 0;
}
solve(0, node_cnt);
}
for (int i=0; i<N; ++i) {
for (auto [v, x] : adj[i]) {
if (i > v) continue;
Bridge(i, v);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
388 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
388 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
388 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
600 KB |
Output is correct |
28 |
Correct |
3 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
3 ms |
672 KB |
Output is correct |
31 |
Correct |
3 ms |
600 KB |
Output is correct |
32 |
Correct |
5 ms |
856 KB |
Output is correct |
33 |
Correct |
4 ms |
600 KB |
Output is correct |
34 |
Correct |
5 ms |
600 KB |
Output is correct |
35 |
Correct |
5 ms |
672 KB |
Output is correct |
36 |
Correct |
3 ms |
660 KB |
Output is correct |
37 |
Correct |
6 ms |
600 KB |
Output is correct |
38 |
Correct |
6 ms |
600 KB |
Output is correct |
39 |
Correct |
6 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
1100 KB |
Output is correct |
2 |
Correct |
204 ms |
1104 KB |
Output is correct |
3 |
Correct |
181 ms |
1100 KB |
Output is correct |
4 |
Correct |
175 ms |
1052 KB |
Output is correct |
5 |
Correct |
206 ms |
1108 KB |
Output is correct |
6 |
Correct |
162 ms |
1180 KB |
Output is correct |
7 |
Correct |
225 ms |
1100 KB |
Output is correct |
8 |
Correct |
242 ms |
1100 KB |
Output is correct |
9 |
Correct |
232 ms |
1164 KB |
Output is correct |
10 |
Correct |
237 ms |
1104 KB |
Output is correct |
11 |
Correct |
253 ms |
1164 KB |
Output is correct |
12 |
Correct |
269 ms |
1152 KB |
Output is correct |
13 |
Correct |
225 ms |
1104 KB |
Output is correct |
14 |
Correct |
240 ms |
1104 KB |
Output is correct |
15 |
Correct |
239 ms |
1104 KB |
Output is correct |
16 |
Correct |
280 ms |
1196 KB |
Output is correct |
17 |
Correct |
222 ms |
1100 KB |
Output is correct |
18 |
Correct |
202 ms |
1192 KB |
Output is correct |
19 |
Correct |
233 ms |
1044 KB |
Output is correct |
20 |
Correct |
245 ms |
1160 KB |
Output is correct |
21 |
Correct |
262 ms |
1168 KB |
Output is correct |
22 |
Correct |
225 ms |
1100 KB |
Output is correct |
23 |
Correct |
223 ms |
1100 KB |
Output is correct |
24 |
Correct |
223 ms |
1104 KB |
Output is correct |
25 |
Correct |
209 ms |
1144 KB |
Output is correct |
26 |
Correct |
207 ms |
1108 KB |
Output is correct |
27 |
Correct |
214 ms |
1104 KB |
Output is correct |
28 |
Correct |
275 ms |
1072 KB |
Output is correct |
29 |
Correct |
214 ms |
1124 KB |
Output is correct |
30 |
Correct |
245 ms |
1396 KB |
Output is correct |
31 |
Correct |
237 ms |
1092 KB |
Output is correct |
32 |
Correct |
469 ms |
1124 KB |
Output is correct |
33 |
Correct |
317 ms |
1104 KB |
Output is correct |
34 |
Correct |
3 ms |
600 KB |
Output is correct |
35 |
Correct |
3 ms |
600 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
3 ms |
600 KB |
Output is correct |
38 |
Correct |
3 ms |
600 KB |
Output is correct |
39 |
Correct |
3 ms |
600 KB |
Output is correct |
40 |
Correct |
4 ms |
652 KB |
Output is correct |
41 |
Correct |
5 ms |
600 KB |
Output is correct |
42 |
Correct |
5 ms |
636 KB |
Output is correct |
43 |
Correct |
3 ms |
600 KB |
Output is correct |
44 |
Correct |
5 ms |
656 KB |
Output is correct |
45 |
Correct |
6 ms |
600 KB |
Output is correct |
46 |
Correct |
6 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
600 KB |
Output is correct |
48 |
Correct |
0 ms |
600 KB |
Output is correct |
49 |
Correct |
0 ms |
600 KB |
Output is correct |
50 |
Correct |
0 ms |
600 KB |
Output is correct |
51 |
Correct |
0 ms |
600 KB |
Output is correct |
52 |
Correct |
0 ms |
600 KB |
Output is correct |
53 |
Correct |
1 ms |
600 KB |
Output is correct |
54 |
Correct |
0 ms |
600 KB |
Output is correct |
55 |
Correct |
1 ms |
600 KB |
Output is correct |
56 |
Correct |
0 ms |
600 KB |
Output is correct |
57 |
Correct |
1 ms |
600 KB |
Output is correct |
58 |
Correct |
0 ms |
600 KB |
Output is correct |
59 |
Correct |
0 ms |
600 KB |
Output is correct |
60 |
Correct |
0 ms |
600 KB |
Output is correct |
61 |
Correct |
0 ms |
600 KB |
Output is correct |
62 |
Correct |
0 ms |
600 KB |
Output is correct |
63 |
Correct |
0 ms |
600 KB |
Output is correct |
64 |
Correct |
0 ms |
600 KB |
Output is correct |
65 |
Correct |
0 ms |
600 KB |
Output is correct |
66 |
Correct |
1 ms |
600 KB |
Output is correct |
67 |
Correct |
0 ms |
600 KB |
Output is correct |
68 |
Correct |
1 ms |
600 KB |
Output is correct |
69 |
Correct |
0 ms |
600 KB |
Output is correct |
70 |
Correct |
0 ms |
600 KB |
Output is correct |
71 |
Correct |
0 ms |
600 KB |
Output is correct |
72 |
Correct |
1 ms |
600 KB |
Output is correct |