#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
class DSU {
private: vector<int> p, rank;
public:
DSU(int n) {
p.assign(n, -1);
for (int i = 0; i < n; i++) p[i] = i;
rank.assign(n, 0);
}
int root(int x) {
return p[x] == x ? x : p[x] = root(p[x]);
}
bool sameSet(int x, int y) {
return root(x) == root(y);
}
void connect(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (rank[x] > rank[y]) p[y] = x;
else {
p[x] = y;
if (rank[x] == rank[y]) rank[y]++;
}
}
return;
}
};
vector<int> ind, bin;
vector<vector<int>> g;
int cnt = 0;
void preorder(int u, int par) {
ind[u] = cnt++;
MessageBoard(u, bin[ind[u] % 60]);
for (int& v : g[u]) {
if (v != par) {
preorder(v, u);
}
}
return;
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
DSU dsu(N);
ind.resize(N);
g.resize(N);
for (int i = 0; i < 60; i++) {
if (X & (1ll << i)) bin.push_back(1);
else bin.push_back(0);
}
//reverse(bin.begin(), bin.end());
//for (int x : bin) printf("%d ", x);
for (int i = 0; i < M; i++) {
if (!dsu.sameSet(A[i], B[i])) {
dsu.connect(A[i], B[i]);
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
preorder(0, -1);
return;
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
class DSU {
private: vector<int> p, rank;
public:
DSU(int n) {
p.assign(n, -1);
for (int i = 0; i < n; i++) p[i] = i;
rank.assign(n, 0);
}
int root(int x) {
return p[x] == x ? x : p[x] = root(p[x]);
}
bool sameSet(int x, int y) {
return root(x) == root(y);
}
void connect(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (rank[x] > rank[y]) p[y] = x;
else {
p[x] = y;
if (rank[x] == rank[y]) rank[y]++;
}
}
}
};
vector<int> ind2;
vector<vector<int>> g2;
vector<int> p;
vector<int> bin2(60, -1);
int needed = 60;
int cnt2 = 0;
int cur;
void preorder2(int u, int par) {
ind2[u] = cnt2++;
for (int& v : g2[u]) {
if (v != par) {
preorder2(v, u);
}
}
}
void dfs(int u) {
//printf("%d %d\n", u, cur);
if (needed <= 0) return;
for (int& v : g2[u]) {
if (v != p[u]) {
if (bin2[ind2[v] % 60] == -1) {
//printf("yep\n");
p[v] = u;
int tmp = Move(v);
//printf("%d ", tmp);
bin2[ind2[v] % 60] = tmp;
//if (tmp == 1) printf("%d\n", ind2[v] % 60);
needed--;
cur = v;
dfs(v);
if (cur != u && needed) Move(u), cur = u;
//printf("yep %d\n", cur);
}
if (needed <= 0) return;
}
}
if (cur != u) /*printf("%d %d\n", cur, u),*/ Move(u), cur = u;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
ind2.resize(N);
DSU dsu(N);
g2.resize(N);
p.resize(N);
cur = P;
for (int i = 0; i < M; i++) {
if (!dsu.sameSet(A[i], B[i])) {
dsu.connect(A[i], B[i]);
g2[A[i]].push_back(B[i]);
g2[B[i]].push_back(A[i]);
}
}
preorder2(0, -1);
//for (int i = 0; i < N; i++) printf("%d %d\n", i, ind2[i]);
bin2[ind2[P] % 60] = V;
//for (int& x : bin2) printf("%d ", x);
long long ans = 0ll;
dfs(P);
//for (int& x : bin2) printf("%d ", x);
for (int i = 0; i < 60; i++) {
//printf("%d ", bin2[i]);
//assert(bin2[i] != -1);
if (bin2[i]) ans += (1ll << i);
//printf("%lld\n", ans);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
752 KB |
Output is correct |
2 |
Correct |
5 ms |
916 KB |
Output is correct |
3 |
Incorrect |
5 ms |
1064 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
3736 KB |
Output is correct |
2 |
Incorrect |
40 ms |
4200 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4208 KB |
Output is correct |
2 |
Correct |
4 ms |
4208 KB |
Output is correct |
3 |
Correct |
5 ms |
4208 KB |
Output is correct |
4 |
Correct |
7 ms |
4208 KB |
Output is correct |
5 |
Correct |
6 ms |
4208 KB |
Output is correct |
6 |
Correct |
7 ms |
4208 KB |
Output is correct |
7 |
Correct |
6 ms |
4208 KB |
Output is correct |
8 |
Correct |
9 ms |
4208 KB |
Output is correct |
9 |
Correct |
19 ms |
5280 KB |
Output is correct |
10 |
Correct |
20 ms |
5472 KB |
Output is correct |
11 |
Correct |
19 ms |
5716 KB |
Output is correct |
12 |
Correct |
5 ms |
5800 KB |
Output is correct |
13 |
Correct |
6 ms |
5800 KB |
Output is correct |
14 |
Correct |
5 ms |
5800 KB |
Output is correct |
15 |
Correct |
4 ms |
5800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
5800 KB |
Output is correct |
2 |
Correct |
33 ms |
5868 KB |
Output is correct |
3 |
Correct |
35 ms |
6500 KB |
Output is correct |
4 |
Correct |
23 ms |
6752 KB |
Output is correct |
5 |
Correct |
26 ms |
6852 KB |
Output is correct |
6 |
Correct |
26 ms |
6880 KB |
Output is correct |
7 |
Correct |
20 ms |
6880 KB |
Output is correct |
8 |
Correct |
22 ms |
6880 KB |
Output is correct |
9 |
Incorrect |
19 ms |
7120 KB |
Wrong Answer [7] |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
7340 KB |
Output is correct |
2 |
Correct |
28 ms |
7748 KB |
Output is correct |
3 |
Correct |
36 ms |
8256 KB |
Output is correct |
4 |
Correct |
19 ms |
8384 KB |
Output is correct |
5 |
Incorrect |
20 ms |
8800 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |