#include "meetings.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
mt19937 rnd(228);
const int N = 2010;
short timer, up[N][20];
vector<short> nh[20], have[N];
vector<pair<short, short>> pars[N];
short ptr[N], color[N], skip[N];
int opers, opers2 ;
bool was[N];
int get_color(int v) {
if (color[v] != -1) {
return color[v];
}
return color[v] = get_color(pars[v][ptr[v]].F);
}
vector<pair<short, short>> edge;
void Solve(int n) {
short root = rnd() % n;
for (int i = 0; i < n; i++) {
have[root].pb(i);
}
assert(n <= 2000);
queue<short> q;
q.push(root);
while (!q.empty()) {
int root = q.front();
assert(!was[root]);
was[root] = true;
q.pop();
if (SZ(have[root]) == 1) {
continue;
}
for (int i = 0; i < SZ(have[root]); i++) {
color[have[root][i]] = -1;
}
short id = (have[root][0] == root ? 1 : 0);
short cc = 1;
nh[0] = {have[root][id]};
up[root][0] = have[root][id];
color[have[root][id]] = 0;
timer++;
for (int i = id + 1; i < SZ(have[root]); i++) {
if (have[root][i] == root) {
continue;
}
while (ptr[have[root][i]] < SZ(pars[have[root][i]]) && was[pars[have[root][i]][ptr[have[root][i]]].S]) {
ptr[have[root][i]]++;
opers2++;
}
if (ptr[have[root][i]] < SZ(pars[have[root][i]]) || color[have[root][i]] != -1) {
skip[have[root][i]] = timer;
continue;
}
for (int j = 0; j < cc; j++) {
opers++;
short v = Query(root, up[root][j], have[root][i]);
if (v != root) {
if (v != up[root][j]) pars[up[root][j]].pb({have[root][i], v});
else pars[have[root][i]].pb({up[root][j], v});
up[root][j] = v;
nh[j].pb(have[root][i]);
color[v] = j;
color[have[root][i]] = j;
break;
}
}
if (color[have[root][i]] == -1) {
nh[cc] = {have[root][i]};
up[root][cc] = have[root][i];
color[have[root][i]] = cc++;
}
}
assert(opers <= (int)n * n);
assert(opers2 <= (int)n * n);
for (int i = 0; i < cc; i++) {
edge.pb({root, up[root][i]});
}
for (int i = 0; i < SZ(have[root]); i++) {
if (have[root][i] != root && skip[have[root][i]] == timer) {
get_color(have[root][i]);
nh[color[have[root][i]]].pb(have[root][i]);
}
}
for (int i = 0; i < cc; i++) {
/*for (int j = 0; j < sz_nh[i]; j++) {
have[up[root][i]][j] = nh[i][j];
}
sz_have[up[root][i]] = sz_nh[i];*/
have[up[root][i]].swap(nh[i]);
}
for (int i = 0; i < cc; i++) {
q.push(up[root][i]);
}
}
for (auto &it : edge) {
if (it.F > it.S) {
swap(it.F, it.S);
}
Bridge(it.F, it.S);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
380 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
380 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
380 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
14 ms |
504 KB |
Output is correct |
28 |
Correct |
14 ms |
632 KB |
Output is correct |
29 |
Correct |
16 ms |
632 KB |
Output is correct |
30 |
Correct |
18 ms |
504 KB |
Output is correct |
31 |
Correct |
17 ms |
496 KB |
Output is correct |
32 |
Correct |
17 ms |
504 KB |
Output is correct |
33 |
Correct |
19 ms |
504 KB |
Output is correct |
34 |
Correct |
22 ms |
504 KB |
Output is correct |
35 |
Correct |
21 ms |
504 KB |
Output is correct |
36 |
Correct |
19 ms |
504 KB |
Output is correct |
37 |
Correct |
61 ms |
760 KB |
Output is correct |
38 |
Correct |
47 ms |
632 KB |
Output is correct |
39 |
Correct |
11 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1226 ms |
1224 KB |
Output is correct |
2 |
Correct |
1091 ms |
1016 KB |
Output is correct |
3 |
Correct |
1151 ms |
1144 KB |
Output is correct |
4 |
Correct |
1183 ms |
1272 KB |
Output is correct |
5 |
Correct |
1157 ms |
1156 KB |
Output is correct |
6 |
Correct |
838 ms |
1144 KB |
Output is correct |
7 |
Correct |
838 ms |
1016 KB |
Output is correct |
8 |
Correct |
938 ms |
1016 KB |
Output is correct |
9 |
Correct |
845 ms |
1016 KB |
Output is correct |
10 |
Correct |
830 ms |
1040 KB |
Output is correct |
11 |
Correct |
1000 ms |
1028 KB |
Output is correct |
12 |
Execution timed out |
3078 ms |
1752 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |