#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
class DSU {
private: vector<int> p, rank;
public:
DSU(int n) {p.assign(n, -1); rank.assign(n, 0); }
int root(int x) { return p[x] < 0 ? 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 (rank[x] > rank[y]) p[y] = x; else { p[x] = y; if (rank[x] == rank[y]) rank[y]++; }}
};
vector<vector<int>> joiG;
vector<int> joiInd;
int joiCnt;
vector<int> joiV;
bitset<60> joiUsedInd;
vector<int> joiOrder;
void joiDfs(int u, int par) {
//joiCnt++;
if (joiCnt >= 60) return;
joiCnt++;
if (joiInd[u] != -1) joiUsedInd[joiInd[u]] = true;
joiV.push_back(u);
for (int& v : joiG[u]) {
if (v != par) {
if (joiInd[v] != -1 && joiUsedInd[joiInd[v]]) continue;
joiDfs(v, u);
}
}
return;
}
void joiPreorder(int u, int par) {
joiOrder.push_back(u);
for (int& v : joiG[u]) {
if (v != par) {
joiPreorder(v, u);
}
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
DSU dsu(N);
joiG.resize(N);
joiInd.assign(N, -1);
for (int i = 0; i < M; i++) {
if (!dsu.sameSet(A[i], B[i])) {
dsu.connect(A[i], B[i]);
joiG[A[i]].push_back(B[i]);
joiG[B[i]].push_back(A[i]);
}
}
joiPreorder(0, -1);
for (int &i : joiOrder) {
joiV.clear();
#ifdef DEBUG
//printf("%d\n", i);
#endif
joiCnt = 0;
joiUsedInd.reset();
joiDfs(i, -1);
//for (int& tmp : joiV)
int cnt = 0;
for (int& v : joiV) {
while (joiUsedInd[cnt]) cnt++;
if (joiInd[v] != -1) continue;
joiInd[v] = cnt++;
}
}
#ifdef DEBUG
for (int i = 0; i < N; i++) {
//printf("%d %d\n", i, joiInd[i]);
}
#endif
vector<int> bin;
for (int i = 0; i < 60; i++) {
if (X & (1ll << i)) bin.push_back(1);
else bin.push_back(0);
}
for (int i = 0; i < N; i++) {
MessageBoard(i, bin[joiInd[i]]);
}
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); rank.assign(n, 0); }
int root(int x) { return p[x] < 0 ? 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 (rank[x] > rank[y]) p[y] = x; else { p[x] = y; if (rank[x] == rank[y]) rank[y]++; } }
};
vector<vector<int>> ioiG;
int ioiCnt;
bitset<60> ioiUsedInd;
vector<int> ioiInd;
vector<int> ioiV;
vector<int> v(60, -1);
bitset<10005> setV;
vector<int> ioiOrder;
int cur, dfsCur;
int _P;
void ioiDfs(int u, int par) {
//ioiCnt++;
if (ioiCnt >= 60) return;
ioiCnt++;
if (ioiInd[u] != -1) ioiUsedInd[ioiInd[u]] = true;
ioiV.push_back(u);
if (cur == _P) setV[u] = true;
for (int& v : ioiG[u]) {
if (v != par) {
if (ioiInd[v] != -1 && ioiUsedInd[ioiInd[v]]) continue;
ioiDfs(v, u);
}
}
return;
}
void ioiPreorder(int u, int par) {
ioiOrder.push_back(u);
for (int& v : ioiG[u]) {
if (v != par) {
ioiPreorder(v, u);
}
}
}
void dfs(int u, int par) {
#ifdef DEBUG
//printf("%d %d\n", u, par);
#endif
for (int& neigh : ioiG[u]) {
if (neigh != par && setV[neigh]) {
int tmp = Move(neigh);
#ifdef DEBUG
//printf("%d\n", tmp);
#endif
v[ioiInd[neigh]] = tmp;
cur = neigh;
dfs(neigh, u);
if (cur != u) {
Move(u);
cur = u;
}
}
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
_P = P;
DSU dsu(N);
ioiG.resize(N);
ioiInd.assign(N, -1);
for (int i = 0; i < M; i++) {
if (!dsu.sameSet(A[i], B[i])) {
dsu.connect(A[i], B[i]);
ioiG[A[i]].push_back(B[i]);
ioiG[B[i]].push_back(A[i]);
}
}
ioiPreorder(0, -1);
for (int& i : ioiOrder) {
ioiV.clear();
ioiCnt = 0;
ioiUsedInd.reset();
cur = i;
ioiDfs(i, -1);
int cnt = 0;
for (int& v : ioiV) {
#ifdef DEBUG
//printf("%d\n", v);
#endif
while (ioiUsedInd[cnt]) cnt++;
if (ioiInd[v] != -1) continue;
ioiInd[v] = cnt++;
#ifdef DEBUG
//printf("%d\n", cnt);
#endif
}
}
#ifdef DEBUG
//for (int i = 0; i < N; i++) printf("%d %d\n", i, ioiInd[i]);
#endif
v[ioiInd[P]] = V;
dfs(P, -1);
#ifdef DEBUG
//for (int& bit : v) printf("%d ", bit);
#endif
//putchar('\n');
long long ans = 0ll;
for (int i = 0; i < 60; i++) {
if (v[i] == 1) ans += (1ll << i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
612 KB |
Output is correct |
2 |
Correct |
4 ms |
836 KB |
Output is correct |
3 |
Correct |
6 ms |
900 KB |
Output is correct |
4 |
Correct |
4 ms |
1092 KB |
Output is correct |
5 |
Correct |
4 ms |
1196 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
6 ms |
1412 KB |
Output is correct |
9 |
Correct |
6 ms |
1424 KB |
Output is correct |
10 |
Correct |
4 ms |
1460 KB |
Output is correct |
11 |
Correct |
10 ms |
1744 KB |
Output is correct |
12 |
Correct |
4 ms |
1744 KB |
Output is correct |
13 |
Correct |
5 ms |
1744 KB |
Output is correct |
14 |
Correct |
5 ms |
1744 KB |
Output is correct |
15 |
Correct |
5 ms |
1744 KB |
Output is correct |
16 |
Correct |
5 ms |
1768 KB |
Output is correct |
17 |
Correct |
8 ms |
1792 KB |
Output is correct |
18 |
Correct |
7 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
4864 KB |
Output is correct |
2 |
Correct |
66 ms |
5416 KB |
Output is correct |
3 |
Correct |
68 ms |
5772 KB |
Output is correct |
4 |
Correct |
63 ms |
5904 KB |
Output is correct |
5 |
Correct |
52 ms |
5992 KB |
Output is correct |
6 |
Correct |
53 ms |
6152 KB |
Output is correct |
7 |
Correct |
68 ms |
6352 KB |
Output is correct |
8 |
Correct |
57 ms |
6596 KB |
Output is correct |
9 |
Correct |
72 ms |
6764 KB |
Output is correct |
10 |
Correct |
947 ms |
6800 KB |
Output is correct |
11 |
Correct |
850 ms |
6988 KB |
Output is correct |
12 |
Correct |
45 ms |
6992 KB |
Output is correct |
13 |
Incorrect |
43 ms |
7184 KB |
Wrong Answer [7] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7184 KB |
Output is correct |
2 |
Correct |
5 ms |
7184 KB |
Output is correct |
3 |
Correct |
4 ms |
7184 KB |
Output is correct |
4 |
Correct |
11 ms |
7184 KB |
Output is correct |
5 |
Correct |
12 ms |
7184 KB |
Output is correct |
6 |
Correct |
10 ms |
7184 KB |
Output is correct |
7 |
Correct |
9 ms |
7184 KB |
Output is correct |
8 |
Correct |
11 ms |
7184 KB |
Output is correct |
9 |
Correct |
55 ms |
8400 KB |
Output is correct |
10 |
Correct |
36 ms |
8668 KB |
Output is correct |
11 |
Correct |
89 ms |
8776 KB |
Output is correct |
12 |
Correct |
5 ms |
8776 KB |
Output is correct |
13 |
Correct |
4 ms |
8776 KB |
Output is correct |
14 |
Correct |
6 ms |
8776 KB |
Output is correct |
15 |
Correct |
4 ms |
8776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
8776 KB |
Output is correct |
2 |
Correct |
64 ms |
9108 KB |
Output is correct |
3 |
Correct |
82 ms |
9744 KB |
Output is correct |
4 |
Correct |
51 ms |
9744 KB |
Output is correct |
5 |
Correct |
65 ms |
10220 KB |
Output is correct |
6 |
Correct |
78 ms |
10256 KB |
Output is correct |
7 |
Correct |
60 ms |
10276 KB |
Output is correct |
8 |
Correct |
78 ms |
10296 KB |
Output is correct |
9 |
Correct |
72 ms |
10352 KB |
Output is correct |
10 |
Correct |
798 ms |
10472 KB |
Output is correct |
11 |
Correct |
955 ms |
10800 KB |
Output is correct |
12 |
Correct |
47 ms |
10888 KB |
Output is correct |
13 |
Correct |
116 ms |
10888 KB |
Output is correct |
14 |
Correct |
47 ms |
11104 KB |
Output is correct |
15 |
Correct |
104 ms |
11232 KB |
Output is correct |
16 |
Correct |
122 ms |
11512 KB |
Output is correct |
17 |
Correct |
55 ms |
11616 KB |
Output is correct |
18 |
Correct |
54 ms |
11868 KB |
Output is correct |
19 |
Correct |
55 ms |
12032 KB |
Output is correct |
20 |
Correct |
50 ms |
12740 KB |
Output is correct |
21 |
Correct |
41 ms |
12872 KB |
Output is correct |
22 |
Correct |
59 ms |
13056 KB |
Output is correct |
23 |
Correct |
55 ms |
13256 KB |
Output is correct |
24 |
Correct |
58 ms |
13428 KB |
Output is correct |
25 |
Correct |
105 ms |
13640 KB |
Output is correct |
26 |
Incorrect |
74 ms |
13832 KB |
Wrong Answer [7] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
14292 KB |
Output is correct |
2 |
Incorrect |
61 ms |
14672 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |