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 "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
static int par[505], ia[505], ib[505], dep[505], n;
static vector<int> gph[505];
static vector<pi> el;
static void dfs(int x, int p){
for(auto &i : gph[x]){
if(i == p) continue;
par[i] = x;
dep[i] = dep[x] + 1;
el.push_back(pi(x, i));
dfs(i, x);
el.push_back(pi(i, x));
}
}
static int getL;
void InitAnya(int N , int A[] , int B[]) {
n = N;
memcpy(ia, A, sizeof(int) * (N-1));
memcpy(ib, B, sizeof(int) * (N-1));
for(int i=0; i<N-1; i++){
gph[ia[i]].push_back(ib[i]);
gph[ib[i]].push_back(ia[i]);
}
dfs(0, -1);
}
int pchk[505], sum[1005];
void Anya(int C[]) {
for(int i=0; i<n-1; i++){
Save(i, C[i]);
if(par[ia[i]] == ib[i]) swap(ia[i], ib[i]);
pchk[ib[i]] = C[i];
}
memset(sum, 0, sizeof(sum));
for(int i=0; i<el.size(); i++){
if(dep[el[i].first] < dep[el[i].second]){
sum[i] = pchk[el[i].second];
}
else{
sum[i] = -pchk[el[i].first];
}
}
for(int i=1; i<=1000; i++) sum[i] += sum[i-1];
int pnt = n - 1;
for(int i=19; i<=999; i+=20){
for(int j=0; j<9; j++){
Save(pnt++, (sum[i] >> j) & 1);
}
}
}
#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
static int par[505], ia[505], ib[505], dep[505], n;
static vector<int> gph[505];
static vector<pi> el;
static void dfs(int x, int p){
for(auto &i : gph[x]){
if(i == p) continue;
par[i] = x;
dep[i] = dep[x] + 1;
el.push_back(pi(x, i));
dfs(i, x);
el.push_back(pi(i, x));
}
}
void InitBoris(int N , int A[] , int B[]) {
memcpy(ia, A, sizeof(int) * (N-1));
memcpy(ib, B, sizeof(int) * (N-1));
n = N;
for(int i=0; i<N-1; i++){
gph[A[i]].push_back(B[i]);
gph[B[i]].push_back(A[i]);
}
dfs(0, -1);
}
int querya(int x){
if(x < 0) return 0;
assert(x % 20 == 19);
x = 9 * (x / 20) + n-1;
int ans = 0;
for(int j=0; j<9; j++){
ans |= (Ask(x + j) << j);
}
return ans;
}
int get_pchk(int node){
for(int i=0; i<n-1; i++){
if(par[ia[i]] == ib[i]) swap(ia[i], ib[i]);
if(ib[i] == node) return Ask(i);
}
assert(0);
}
int queryb(int x){
if(x >= el.size()) return 0;
if(dep[el[x].first] < dep[el[x].second]){
return get_pchk(el[x].second);
}
else return -get_pchk(el[x].first);
}
int Boris(int city) {
int gs = 0;
for(int i=0; i<el.size(); i++){
if(el[i].second == city){
gs = i;
break;
}
}
if(gs % 20 >= 10){
int up = (gs / 20 + 1) * 20;
int sum = querya(up - 1);
for(int i=gs+1; i<up; i++){
sum -= queryb(i);
}
return sum;
}
else{
int up = (gs / 20) * 20;
int sum = querya(up - 1);
for(int i=up; i<=gs; i++){
sum += queryb(i);
}
return sum;
}
}
Compilation message (stderr)
Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:44:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<el.size(); i++){
^
Anya.cpp: At global scope:
Anya.cpp:22:12: warning: 'getL' defined but not used [-Wunused-variable]
static int getL;
^
Boris.cpp: In function 'int queryb(int)':
Boris.cpp:53:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(x >= el.size()) return 0;
^
Boris.cpp: In function 'int Boris(int)':
Boris.cpp:62:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<el.size(); i++){
^
# | 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... |