#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
#define ll long long
const int NA = 10001;
const int KA = 60;
int mxA[NA], pA[NA], tA[NA], dfstimeA;
vector <int> vA[NA];
int findA(int x){
if(pA[x] == x) return x;
return pA[x] = findA(pA[x]);
}
bool mergeA(int x, int y){
x = findA(x);
y = findA(y);
if(x == y) return 0;
pA[x] = y;
return 1;
}
void dfszA(int node, int pnode){
for(auto &i : vA[node]){
if(i == pnode) continue;
dfszA(i, node);
mxA[node] = max(mxA[node], mxA[i] + 1);
}
}
void dfsA(int node, int pnode){
tA[node] = dfstimeA++;
for(auto &i : vA[node]){
if(i == pnode) continue;
dfsA(i, node);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
for(int i = 0 ; i < N ; i++){
pA[i] = i;
}
for(int i = 0 ; i < M ; i++){
if(mergeA(A[i], B[i])){
vA[A[i]].push_back(B[i]);
vA[B[i]].push_back(A[i]);
}
}
dfszA(0, 0);
for(int i = 0 ; i < N ; i++){
sort(vA[i].begin(), vA[i].end(), [&](int l, int r){
return mxA[l] > mxA[r];
});
}
dfsA(0, 0);
for(int i = 0 ; i < N ; i++){
MessageBoard(i, (X >> (tA[i] % KA)) & 1);
}
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
#define ll long long
const int NB = 10001;
const int KB = 60;
int mxB[NB], pB[NB], tB[NB], szB[NB], XB[KB], unknownB = KB, dfstimeB;
vector <int> vB[NB];
void updateB(int bit, int v){
if(XB[bit] == -1){
unknownB--;
XB[bit] = v;
}
}
int findB(int x){
if(pB[x] == x) return x;
return pB[x] = findB(pB[x]);
}
bool mergeB(int x, int y){
x = findB(x);
y = findB(y);
if(x == y) return 0;
pB[x] = y;
return 1;
}
void dfszB(int node, int pnode){
for(auto &i : vB[node]){
if(i == pnode) continue;
dfszB(i, node);
mxB[node] = max(mxB[node], mxB[i] + 1);
}
}
void dfsB(int node, int pnode){
szB[node] = 1;
tB[node] = dfstimeB++;
for(auto &i : vB[node]){
if(i == pnode) continue;
pB[i] = node;
dfsB(i, node);
szB[node] += szB[i];
}
}
void my_moveB(int dest){
int v = Move(dest);
assert(0 <= v && v <= 1);
updateB(tB[dest] % KB, v);
}
void solveB(int node, int k){
if(unknownB == 0) return;
vector <int> all;
for(auto &i : vB[node]){
if(unknownB == 0) return;
if(k == 0) break;
if(k < szB[i]){
my_moveB(i);
solveB(i, k);
break;
}
else{
all.push_back(i);
k -= szB[i];
}
}
reverse(all.begin(), all.end());
for(auto &i : all){
if(unknownB == 0) return;
my_moveB(i);
solveB(i, szB[i]);
}
if(unknownB == 0) return;
if(pB[node] != -1) my_moveB(pB[node]);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
for(int i = 0 ; i < KB ; i++){
XB[i] = -1;
}
for(int i = 0 ; i < N ; i++){
pB[i] = i;
}
for(int i = 0 ; i < M ; i++){
if(mergeB(A[i], B[i])){
vB[A[i]].push_back(B[i]);
vB[B[i]].push_back(A[i]);
}
}
dfszB(0, 0);
for(int i = 0 ; i < N ; i++){
sort(vB[i].begin(), vB[i].end(), [&](int l, int r){
return mxB[l] > mxB[r];
});
}
pB[0] = -1;
dfsB(0, 0);
for(int i = 1 ; i < N ; i++){
vB[i].erase(find(vB[i].begin(), vB[i].end(), pB[i]));
}
int node = P;
int v = V;
updateB(tB[node] % KB, v);
while(szB[node] < KB){
my_moveB(pB[node]);
node = pB[node];
}
solveB(node, KB);
ll X = 0;
for(int i = KB - 1 ; i >= 0 ; i--){
X = 2 * X + XB[i];
}
return X;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1004 KB |
Output is correct |
2 |
Correct |
2 ms |
1000 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
2 ms |
1092 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1136 KB |
Output is correct |
8 |
Correct |
2 ms |
1264 KB |
Output is correct |
9 |
Correct |
2 ms |
1012 KB |
Output is correct |
10 |
Correct |
2 ms |
1004 KB |
Output is correct |
11 |
Correct |
5 ms |
1332 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
2 ms |
1004 KB |
Output is correct |
14 |
Correct |
2 ms |
1008 KB |
Output is correct |
15 |
Correct |
2 ms |
1008 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
2 ms |
1008 KB |
Output is correct |
18 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3452 KB |
Output is correct |
2 |
Correct |
26 ms |
3704 KB |
Output is correct |
3 |
Correct |
26 ms |
3632 KB |
Output is correct |
4 |
Correct |
17 ms |
2808 KB |
Output is correct |
5 |
Correct |
16 ms |
3464 KB |
Output is correct |
6 |
Correct |
16 ms |
3344 KB |
Output is correct |
7 |
Correct |
16 ms |
3340 KB |
Output is correct |
8 |
Correct |
16 ms |
3356 KB |
Output is correct |
9 |
Correct |
17 ms |
3432 KB |
Output is correct |
10 |
Correct |
14 ms |
3084 KB |
Output is correct |
11 |
Correct |
17 ms |
3040 KB |
Output is correct |
12 |
Correct |
15 ms |
2776 KB |
Output is correct |
13 |
Correct |
14 ms |
2864 KB |
Output is correct |
14 |
Correct |
16 ms |
2816 KB |
Output is correct |
15 |
Correct |
16 ms |
2808 KB |
Output is correct |
16 |
Correct |
16 ms |
2856 KB |
Output is correct |
17 |
Correct |
17 ms |
2956 KB |
Output is correct |
18 |
Correct |
20 ms |
2852 KB |
Output is correct |
19 |
Correct |
18 ms |
2864 KB |
Output is correct |
20 |
Correct |
14 ms |
3608 KB |
Output is correct |
21 |
Correct |
13 ms |
3596 KB |
Output is correct |
22 |
Correct |
16 ms |
3336 KB |
Output is correct |
23 |
Correct |
17 ms |
3324 KB |
Output is correct |
24 |
Correct |
17 ms |
3320 KB |
Output is correct |
25 |
Correct |
16 ms |
3292 KB |
Output is correct |
26 |
Correct |
16 ms |
3432 KB |
Output is correct |
27 |
Correct |
18 ms |
3536 KB |
Output is correct |
28 |
Correct |
17 ms |
3344 KB |
Output is correct |
29 |
Correct |
14 ms |
3248 KB |
Output is correct |
30 |
Correct |
16 ms |
3352 KB |
Output is correct |
31 |
Correct |
2 ms |
1056 KB |
Output is correct |
32 |
Correct |
2 ms |
1076 KB |
Output is correct |
33 |
Correct |
2 ms |
1088 KB |
Output is correct |
34 |
Correct |
2 ms |
1004 KB |
Output is correct |
35 |
Correct |
2 ms |
1004 KB |
Output is correct |
36 |
Correct |
2 ms |
1004 KB |
Output is correct |
37 |
Correct |
2 ms |
1004 KB |
Output is correct |
38 |
Correct |
2 ms |
1016 KB |
Output is correct |
39 |
Correct |
2 ms |
1080 KB |
Output is correct |
40 |
Correct |
2 ms |
1004 KB |
Output is correct |
41 |
Correct |
2 ms |
1004 KB |
Output is correct |
42 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1012 KB |
Output is correct |
2 |
Correct |
2 ms |
1000 KB |
Output is correct |
3 |
Correct |
2 ms |
1004 KB |
Output is correct |
4 |
Correct |
3 ms |
1556 KB |
Output is correct |
5 |
Correct |
3 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1536 KB |
Output is correct |
7 |
Correct |
3 ms |
1552 KB |
Output is correct |
8 |
Correct |
3 ms |
1556 KB |
Output is correct |
9 |
Correct |
14 ms |
4108 KB |
Output is correct |
10 |
Correct |
14 ms |
4108 KB |
Output is correct |
11 |
Correct |
14 ms |
4060 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
2 ms |
1008 KB |
Output is correct |
14 |
Correct |
2 ms |
1004 KB |
Output is correct |
15 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
28 ms |
3580 KB |
Partially correct |
2 |
Correct |
27 ms |
3676 KB |
Output is correct |
3 |
Partially correct |
27 ms |
3708 KB |
Partially correct |
4 |
Correct |
18 ms |
2820 KB |
Output is correct |
5 |
Correct |
17 ms |
3808 KB |
Output is correct |
6 |
Correct |
19 ms |
3396 KB |
Output is correct |
7 |
Correct |
17 ms |
3352 KB |
Output is correct |
8 |
Correct |
17 ms |
3088 KB |
Output is correct |
9 |
Correct |
17 ms |
3468 KB |
Output is correct |
10 |
Correct |
17 ms |
3260 KB |
Output is correct |
11 |
Correct |
16 ms |
3088 KB |
Output is correct |
12 |
Partially correct |
14 ms |
2876 KB |
Partially correct |
13 |
Partially correct |
15 ms |
2800 KB |
Partially correct |
14 |
Partially correct |
16 ms |
2840 KB |
Partially correct |
15 |
Partially correct |
16 ms |
2824 KB |
Partially correct |
16 |
Partially correct |
16 ms |
2824 KB |
Partially correct |
17 |
Correct |
17 ms |
2900 KB |
Output is correct |
18 |
Correct |
18 ms |
2824 KB |
Output is correct |
19 |
Partially correct |
18 ms |
2808 KB |
Partially correct |
20 |
Correct |
14 ms |
3560 KB |
Output is correct |
21 |
Correct |
13 ms |
3600 KB |
Output is correct |
22 |
Correct |
17 ms |
3340 KB |
Output is correct |
23 |
Correct |
18 ms |
3280 KB |
Output is correct |
24 |
Correct |
18 ms |
3340 KB |
Output is correct |
25 |
Correct |
16 ms |
3340 KB |
Output is correct |
26 |
Correct |
17 ms |
3324 KB |
Output is correct |
27 |
Correct |
16 ms |
3588 KB |
Output is correct |
28 |
Correct |
17 ms |
3492 KB |
Output is correct |
29 |
Correct |
16 ms |
3172 KB |
Output is correct |
30 |
Correct |
16 ms |
3332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3656 KB |
Output is correct |
2 |
Incorrect |
26 ms |
3680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |