#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
void Joi(int N, int M, int A[], int B[], long long X, int T) {
struct DSU {
vector<int> p;
DSU() = default;
DSU(int n) : p(n) {
iota(p.begin(), p.end(), 0);
}
int leader(int x) {
while (x != p[x]) x = p[x] = p[p[x]];
return x;
}
bool unite(int x, int y) {
x = leader(x), y = leader(y);
if (p[y] == x) {
return false;
} else {
return p[y] = x, true;
}
}
};
vector<int> tin(N), par(N, -1);
vector<vector<int>> g(N), adj(N);
DSU d(N);
for (int i = 0; i < M; ++i) {
if (d.unite(A[i], B[i])) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
int timer = 0;
function<void(int)> dfs = [&](int v) {
tin[v] = timer++;
sort(g[v].begin(), g[v].end());
for (int to : g[v]) {
if (to != par[v]) {
par[to] = v;
adj[v].push_back(to);
dfs(to);
}
}
swap(g[v], adj[v]);
};
dfs(0);
for (int i = 0; i < N; ++i) {
MessageBoard(i, X >> (tin[i] % 60) & 1);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
struct DSU {
vector<int> p;
DSU() = default;
DSU(int n) : p(n) {
iota(p.begin(), p.end(), 0);
}
int leader(int x) {
while (x != p[x]) x = p[x] = p[p[x]];
return x;
}
bool unite(int x, int y) {
x = leader(x), y = leader(y);
if (p[y] == x) {
return false;
} else {
return p[y] = x, true;
}
}
};
vector<int> tin(N), par(N, -1);
vector<vector<int>> g(N), adj(N);
DSU d(N);
for (int i = 0; i < M; ++i) {
if (d.unite(A[i], B[i])) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
int timer = 0;
function<void(int)> dfs = [&](int v) {
tin[v] = timer++;
sort(g[v].begin(), g[v].end());
for (int to : g[v]) {
if (to != par[v]) {
par[to] = v;
adj[v].push_back(to);
dfs(to);
}
}
};
dfs(0);
int LOG = 60;
vector<bool> used(N);
vector<int> ans(LOG, -1);
ans[tin[P] % LOG] = V;
vector<int> last(N, -1);
int x = P;
while (find(ans.begin(), ans.end(), -1) != ans.end()) {
used[x] = true;
auto it = upper_bound(adj[x].begin(), adj[x].end(), last[x]);
if (it == adj[x].end()) {
it = adj[x].begin();
}
if (adj[x].empty() || used[*it]) {
last[par[x]] = x;
x = par[x];
assert(x != -1);
ans[tin[x] % LOG] = Move(x);
} else {
last[x] = *it;
x = *it;
ans[tin[x] % LOG] = Move(x);
}
}
ll X = 0;
for (int i = 0; i < LOG; ++i) {
assert(ans[i] != -1);
X += ans[i] * (1LL << i);
}
return X;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
524 KB |
Output is correct |
3 |
Correct |
2 ms |
772 KB |
Output is correct |
4 |
Correct |
1 ms |
656 KB |
Output is correct |
5 |
Correct |
1 ms |
524 KB |
Output is correct |
6 |
Correct |
1 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
776 KB |
Output is correct |
8 |
Correct |
2 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
776 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
516 KB |
Output is correct |
13 |
Correct |
1 ms |
776 KB |
Output is correct |
14 |
Correct |
1 ms |
776 KB |
Output is correct |
15 |
Correct |
1 ms |
784 KB |
Output is correct |
16 |
Correct |
2 ms |
784 KB |
Output is correct |
17 |
Correct |
2 ms |
784 KB |
Output is correct |
18 |
Correct |
2 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
4352 KB |
Output is correct |
2 |
Correct |
23 ms |
4252 KB |
Output is correct |
3 |
Correct |
20 ms |
4252 KB |
Output is correct |
4 |
Correct |
17 ms |
3592 KB |
Output is correct |
5 |
Correct |
18 ms |
4636 KB |
Output is correct |
6 |
Correct |
14 ms |
4144 KB |
Output is correct |
7 |
Correct |
17 ms |
4248 KB |
Output is correct |
8 |
Correct |
15 ms |
4380 KB |
Output is correct |
9 |
Correct |
15 ms |
4336 KB |
Output is correct |
10 |
Correct |
14 ms |
3508 KB |
Output is correct |
11 |
Correct |
15 ms |
3600 KB |
Output is correct |
12 |
Correct |
13 ms |
3352 KB |
Output is correct |
13 |
Correct |
12 ms |
3488 KB |
Output is correct |
14 |
Correct |
17 ms |
3344 KB |
Output is correct |
15 |
Correct |
15 ms |
3760 KB |
Output is correct |
16 |
Correct |
14 ms |
3760 KB |
Output is correct |
17 |
Correct |
14 ms |
3664 KB |
Output is correct |
18 |
Correct |
15 ms |
3616 KB |
Output is correct |
19 |
Correct |
14 ms |
3636 KB |
Output is correct |
20 |
Correct |
12 ms |
4408 KB |
Output is correct |
21 |
Correct |
12 ms |
4412 KB |
Output is correct |
22 |
Correct |
14 ms |
4000 KB |
Output is correct |
23 |
Correct |
14 ms |
4252 KB |
Output is correct |
24 |
Correct |
16 ms |
4108 KB |
Output is correct |
25 |
Correct |
14 ms |
4268 KB |
Output is correct |
26 |
Correct |
16 ms |
4252 KB |
Output is correct |
27 |
Correct |
18 ms |
4272 KB |
Output is correct |
28 |
Correct |
16 ms |
4396 KB |
Output is correct |
29 |
Correct |
12 ms |
3980 KB |
Output is correct |
30 |
Correct |
14 ms |
4004 KB |
Output is correct |
31 |
Correct |
1 ms |
656 KB |
Output is correct |
32 |
Correct |
2 ms |
524 KB |
Output is correct |
33 |
Correct |
2 ms |
776 KB |
Output is correct |
34 |
Correct |
1 ms |
608 KB |
Output is correct |
35 |
Correct |
0 ms |
608 KB |
Output is correct |
36 |
Correct |
1 ms |
516 KB |
Output is correct |
37 |
Correct |
1 ms |
524 KB |
Output is correct |
38 |
Correct |
1 ms |
616 KB |
Output is correct |
39 |
Correct |
1 ms |
524 KB |
Output is correct |
40 |
Correct |
1 ms |
524 KB |
Output is correct |
41 |
Correct |
1 ms |
656 KB |
Output is correct |
42 |
Correct |
1 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
1456 KB |
Output is correct |
5 |
Correct |
3 ms |
1460 KB |
Output is correct |
6 |
Correct |
3 ms |
1464 KB |
Output is correct |
7 |
Correct |
2 ms |
1436 KB |
Output is correct |
8 |
Correct |
3 ms |
1460 KB |
Output is correct |
9 |
Correct |
12 ms |
5672 KB |
Output is correct |
10 |
Correct |
12 ms |
5640 KB |
Output is correct |
11 |
Correct |
14 ms |
5684 KB |
Output is correct |
12 |
Correct |
1 ms |
524 KB |
Output is correct |
13 |
Correct |
1 ms |
528 KB |
Output is correct |
14 |
Correct |
1 ms |
516 KB |
Output is correct |
15 |
Correct |
1 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
22 ms |
4204 KB |
Partially correct |
2 |
Correct |
22 ms |
4248 KB |
Output is correct |
3 |
Correct |
24 ms |
4188 KB |
Output is correct |
4 |
Correct |
14 ms |
3640 KB |
Output is correct |
5 |
Correct |
16 ms |
5080 KB |
Output is correct |
6 |
Correct |
19 ms |
4316 KB |
Output is correct |
7 |
Correct |
16 ms |
4408 KB |
Output is correct |
8 |
Correct |
17 ms |
4008 KB |
Output is correct |
9 |
Correct |
14 ms |
4140 KB |
Output is correct |
10 |
Correct |
14 ms |
3512 KB |
Output is correct |
11 |
Correct |
14 ms |
3516 KB |
Output is correct |
12 |
Correct |
13 ms |
3336 KB |
Output is correct |
13 |
Correct |
12 ms |
3316 KB |
Output is correct |
14 |
Correct |
14 ms |
3336 KB |
Output is correct |
15 |
Correct |
16 ms |
3764 KB |
Output is correct |
16 |
Correct |
14 ms |
3748 KB |
Output is correct |
17 |
Correct |
15 ms |
3616 KB |
Output is correct |
18 |
Correct |
15 ms |
3624 KB |
Output is correct |
19 |
Partially correct |
15 ms |
3600 KB |
Partially correct |
20 |
Correct |
13 ms |
4536 KB |
Output is correct |
21 |
Correct |
11 ms |
4388 KB |
Output is correct |
22 |
Correct |
14 ms |
4260 KB |
Output is correct |
23 |
Correct |
15 ms |
4148 KB |
Output is correct |
24 |
Correct |
14 ms |
4124 KB |
Output is correct |
25 |
Correct |
14 ms |
4252 KB |
Output is correct |
26 |
Correct |
14 ms |
4240 KB |
Output is correct |
27 |
Correct |
15 ms |
4392 KB |
Output is correct |
28 |
Correct |
15 ms |
4028 KB |
Output is correct |
29 |
Correct |
13 ms |
3820 KB |
Output is correct |
30 |
Correct |
14 ms |
4136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4324 KB |
Output is correct |
2 |
Correct |
20 ms |
4232 KB |
Output is correct |
3 |
Incorrect |
20 ms |
4168 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |