This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
void send(int idx, int bit){
MessageBoard(idx, bit);
}
const int N = (int)1e4 + 3;
const int LOG = 60;
vector<int> T[N];
int tin[N]; // modulo LOG
int cnt;
void dfs(int u){
if(tin[u] != -1){
return;
}
tin[u] = cnt ++ ;
cnt %= LOG;
for(auto p : T[u]){
dfs(p);
}
}
void Joi(int n, int m, int A[], int B[], ll X, int useless) {
for(int i = 0 ; i < n; i ++ )
tin[i] = -1;
for(int i = 0 ; i < m ; i ++ ){
T[A[i]].push_back(B[i]);
T[B[i]].push_back(A[i]);
}
dfs(0);
for(int i = 0 ; i < n; i ++ ){
if(X & (1ll << tin[i])){
send(i, 1);
}
else{
send(i, 0);
}
}
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int MAXN = (int)1e4 + 9;
const int LG = 60;
vector<int> TT[MAXN];
int ti[MAXN];
int cn;
void gt(int u){
if(ti[u] != -1) return;
ti[u] = cn ++ ;
cn %= LG;
for(auto p : TT[u]){
gt(p);
}
}
int pv[LG][MAXN];
set<int> rem;
int match[LG];
ll Ioi(int n, int m, int a[], int b[], int p, int v, int useless) {
for(int i = 0 ; i < m ; i ++ ){
TT[a[i]].push_back(b[i]);
TT[b[i]].push_back(a[i]);
}
for(int i = 0 ; i < n ; i ++ )
ti[i] = -1;
gt(0);
int node;
for(int i = 0 ; i < LG; i ++ ) {
for(int j = 0 ; j < n; j ++ )
pv[i][j] = -1;
queue<int> ff;
for(int j = 0 ; j < n; j ++){
if(ti[j] == i){
pv[i][j] = j;
ff.push(j);
}
}
while(!ff.empty()){
node = ff.front();
ff.pop();
for(auto p : TT[node]){
if(pv[i][p] == -1){
pv[i][p] = node;
ff.push(p);
}
}
}
}
for(int i = 0 ; i < LG; i ++ )
rem.insert(i);
rem.erase(ti[p]);
match[ti[p]] = v;
int go;
int bit;
while(!rem.empty()){
go = *rem.begin();
do{
bit = Move(pv[go][p]);
p = pv[go][p];
if(rem.count(ti[p])){
rem.erase(ti[p]);
match[ti[p]] = bit;
}
}while(pv[go][p] != p);
}
ll ret = 0;
for(int i = 0 ; i < LG; i ++ )
ret += match[i] * (1ll << i);
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |