#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;
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 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]);
}
}
for (int i = 0; i < N; i++) {
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;
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 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]);
}
}
for (int i = 0; i < N; i++) {
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 |
4 ms |
736 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
5 ms |
1200 KB |
Output is correct |
4 |
Correct |
4 ms |
1528 KB |
Output is correct |
5 |
Correct |
5 ms |
1608 KB |
Output is correct |
6 |
Correct |
4 ms |
1688 KB |
Output is correct |
7 |
Correct |
6 ms |
1688 KB |
Output is correct |
8 |
Correct |
6 ms |
1688 KB |
Output is correct |
9 |
Correct |
7 ms |
1688 KB |
Output is correct |
10 |
Correct |
4 ms |
1744 KB |
Output is correct |
11 |
Correct |
12 ms |
1816 KB |
Output is correct |
12 |
Correct |
4 ms |
1844 KB |
Output is correct |
13 |
Correct |
6 ms |
1872 KB |
Output is correct |
14 |
Correct |
9 ms |
1872 KB |
Output is correct |
15 |
Correct |
7 ms |
1872 KB |
Output is correct |
16 |
Correct |
5 ms |
1872 KB |
Output is correct |
17 |
Correct |
5 ms |
1872 KB |
Output is correct |
18 |
Correct |
5 ms |
1872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
4296 KB |
Output is correct |
2 |
Correct |
98 ms |
4552 KB |
Output is correct |
3 |
Correct |
105 ms |
4552 KB |
Output is correct |
4 |
Correct |
81 ms |
4552 KB |
Output is correct |
5 |
Correct |
91 ms |
4552 KB |
Output is correct |
6 |
Correct |
90 ms |
4552 KB |
Output is correct |
7 |
Correct |
94 ms |
4552 KB |
Output is correct |
8 |
Correct |
89 ms |
4552 KB |
Output is correct |
9 |
Correct |
90 ms |
4656 KB |
Output is correct |
10 |
Correct |
1550 ms |
4852 KB |
Output is correct |
11 |
Correct |
1538 ms |
5272 KB |
Output is correct |
12 |
Correct |
67 ms |
5272 KB |
Output is correct |
13 |
Correct |
63 ms |
5292 KB |
Output is correct |
14 |
Correct |
72 ms |
5364 KB |
Output is correct |
15 |
Correct |
105 ms |
5752 KB |
Output is correct |
16 |
Correct |
106 ms |
6008 KB |
Output is correct |
17 |
Correct |
82 ms |
6240 KB |
Output is correct |
18 |
Correct |
95 ms |
6352 KB |
Output is correct |
19 |
Correct |
81 ms |
6584 KB |
Output is correct |
20 |
Correct |
72 ms |
6776 KB |
Output is correct |
21 |
Correct |
40 ms |
6776 KB |
Output is correct |
22 |
Incorrect |
75 ms |
7176 KB |
Wrong Answer [7] |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7176 KB |
Output is correct |
2 |
Correct |
4 ms |
7176 KB |
Output is correct |
3 |
Correct |
5 ms |
7176 KB |
Output is correct |
4 |
Correct |
11 ms |
7176 KB |
Output is correct |
5 |
Correct |
8 ms |
7176 KB |
Output is correct |
6 |
Correct |
8 ms |
7176 KB |
Output is correct |
7 |
Correct |
8 ms |
7176 KB |
Output is correct |
8 |
Correct |
8 ms |
7176 KB |
Output is correct |
9 |
Correct |
33 ms |
7176 KB |
Output is correct |
10 |
Correct |
32 ms |
7176 KB |
Output is correct |
11 |
Correct |
32 ms |
7176 KB |
Output is correct |
12 |
Correct |
5 ms |
7176 KB |
Output is correct |
13 |
Correct |
4 ms |
7176 KB |
Output is correct |
14 |
Correct |
4 ms |
7176 KB |
Output is correct |
15 |
Correct |
6 ms |
7176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
7608 KB |
Output is correct |
2 |
Correct |
102 ms |
7608 KB |
Output is correct |
3 |
Incorrect |
100 ms |
7676 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
7888 KB |
Output is correct |
2 |
Correct |
97 ms |
7888 KB |
Output is correct |
3 |
Correct |
106 ms |
7888 KB |
Output is correct |
4 |
Correct |
92 ms |
7888 KB |
Output is correct |
5 |
Correct |
80 ms |
7888 KB |
Output is correct |
6 |
Correct |
90 ms |
7888 KB |
Output is correct |
7 |
Incorrect |
94 ms |
7888 KB |
Wrong Answer [7] |
8 |
Halted |
0 ms |
0 KB |
- |