#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) {
const static int maxn = 1e4 + 5;
static int lab[maxn];
static int nTime = 0;
static int id[maxn];
static long long res = 0;
static long long cal = 0;
static vector<int> adj[maxn];
fill_n(lab,maxn,-1);
function<int(int)> FindLab = [&](int u){
return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);
};
for(int i = 0 ; i < M ; ++i){
int s = FindLab(A[i]);
int d = FindLab(B[i]);
if(s != d){
if(lab[s] > lab[d])swap(s , d);
lab[s] += lab[d];
lab[d] = s;
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
}
function<void(int,int)> DFS = [&](int u , int par){
id[u] = nTime;
++nTime;
nTime %= 60;
for(int c : adj[u]){
if(c != par){
DFS(c , u);
}
}
};
DFS(0 , -1);
for(int i = 0 ; i < N ; ++i){
MessageBoard(i , (X >> id[i]) & 1);
}
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
const static int maxn = 1e4 + 5;
static int lab[maxn];
static int nTime = 0;
static int id[maxn];
static long long res = 0;
static long long cal = 0;
static int sub[maxn] , h[maxn];
static long long can[maxn];
static int p[maxn];
static vector<int> adj[maxn];
static vector<int> child[maxn];
fill_n(lab,maxn,-1);
function<int(int)> FindLab = [&](int u){
return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);
};
for(int i = 0 ; i < M ; ++i){
int s = FindLab(A[i]);
int d = FindLab(B[i]);
if(s != d){
if(lab[s] > lab[d])swap(s , d);
lab[s] += lab[d];
lab[d] = s;
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
}
function<void(int,int)> DFS = [&](int u , int par){
id[u] = nTime;
++nTime;
nTime %= 60;
sub[u] = 1;
for(int c : adj[u]){
if(c != par){
child[u].push_back(c);
p[c] = u;
DFS(c , u);
sub[u] += sub[c];
}
}
};
int lim = 60;
function<void(int,int)> DFS3 = [&](int u , int par){
lim--;
h[u] = -1e9;
if(lim <= 0)return;
can[u] = (1ll << id[u]);
sub[u] = 1;
for(int c : child[u]){
if(c != par){
p[c] = u;
DFS3(c , u);
h[u] = max(h[u] , h[c] + 1);
can[u] |= can[c];
}
}
};
DFS(0 , -1);
function<void(int)> DFS2 = [&](int u){
cal |= (1ll << id[u]);
if(V)res |= (1ll << id[u]);
for(int c : child[u]){
if(__builtin_popcountll(cal) == 60)return;
if((~cal) & can[c]){
V = Move(c);
DFS2(c);
V = Move(u);
}
}
};
function<void(int)> DFS1 = [&](int u){
cal |= (1ll << id[u]);
if(V)res |= (1ll << id[u]);
if(child[u].empty())return;
int best = -1;
for(int c : child[u]){
if(__builtin_popcountll(cal) == 60)return;
if((~cal) & can[c]){
if(best == -1 || h[best] < h[c])best = c;
}
}
for(int c : child[u]){
if(__builtin_popcountll(cal) == 60)return;
if(c == best)continue;
if((~cal) & can[c]){
V = Move(c);
DFS2(c);
V = Move(u);
}
}
if(best != -1 && ((~cal) & can[best])){
V = Move(best);
DFS1(best);
}
};
while(sub[P] < 60){
cal |= (1ll << id[P]);
if(V)res |= (1ll << id[P]);
V = Move(p[P]);
P = p[P];
}
DFS3(P , -1);
DFS1(P);
return res;
}
Compilation message
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:10:22: warning: unused variable 'res' [-Wunused-variable]
static long long res = 0;
^~~
Joi.cpp:11:22: warning: unused variable 'cal' [-Wunused-variable]
static long long cal = 0;
^~~
Joi.cpp: At global scope:
Joi.cpp:11:22: warning: 'cal' defined but not used [-Wunused-variable]
Joi.cpp:10:22: warning: 'res' defined but not used [-Wunused-variable]
static long long res = 0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1736 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1660 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
4308 KB |
Output is correct |
2 |
Correct |
32 ms |
4392 KB |
Output is correct |
3 |
Correct |
32 ms |
4480 KB |
Output is correct |
4 |
Correct |
19 ms |
3640 KB |
Output is correct |
5 |
Correct |
22 ms |
4376 KB |
Output is correct |
6 |
Incorrect |
23 ms |
4260 KB |
Wrong Answer [7] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1652 KB |
Output is correct |
2 |
Correct |
5 ms |
1708 KB |
Output is correct |
3 |
Correct |
6 ms |
1524 KB |
Output is correct |
4 |
Correct |
7 ms |
2208 KB |
Output is correct |
5 |
Correct |
7 ms |
2216 KB |
Output is correct |
6 |
Correct |
7 ms |
2304 KB |
Output is correct |
7 |
Incorrect |
8 ms |
2208 KB |
Wrong Answer [7] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
4480 KB |
Output is correct |
2 |
Correct |
31 ms |
4616 KB |
Output is correct |
3 |
Correct |
32 ms |
4476 KB |
Output is correct |
4 |
Correct |
20 ms |
3480 KB |
Output is correct |
5 |
Correct |
23 ms |
4888 KB |
Output is correct |
6 |
Incorrect |
22 ms |
4384 KB |
Wrong Answer [7] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
4488 KB |
Output is correct |
2 |
Incorrect |
31 ms |
4364 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |