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 <vector>
using namespace std;
int _N;
int u[500], v[500];
int h;
vector<int> eix[500];
//L<-road|hub
int to(int src,int eix) {
if (u[eix] == src) return v[eix];
return u[eix];
}
int dfsa(int x,int from,int s,int *C) {
int len = 0;
for (auto ix : eix[x]) {
int dst = to(x,ix);
if (from == dst) continue;
if (C[ix]) Save(999-dst,1);
int dist = dfsa(dst,x,s+C[ix],C);
if (len < dist) len = dist;
}
++len;
if (x && len > 11) {//hub
int pos = h * 9;
while (s) {
Save(pos++,s&1);
s >>= 1;
}
len = 0;
++h;
}
return len;
}
void InitAnya(int N , int A[] , int B[]) {
_N = N;
for (int i = 0; i < N - 1; ++i) {
u[i] = A[i], v[i] = B[i];
eix[A[i]].push_back(i);
eix[B[i]].push_back(i);
}
}
void Anya(int C[]) {
h = 0;
dfsa(0,-1,0,C);
}
#include "Borislib.h"
#include <vector>
using namespace std;
vector<int> edge[500];
int __N;
int k,hub[500],p[500];
int dfsb(int x,int from) {
int len = 0;
for (auto to : edge[x]) {
if (to == from) continue;
int dist = dfsb(to,x);
p[to] = x;
if (len < dist) len = dist;
}
++len;
if (x && len > 11) hub[x] = ++k,len=0;
return len;
}
void InitBoris(int N , int A[] , int B[]) {
__N = N;
for (int i = 0; i < N - 1; ++i) {
edge[A[i]].push_back(B[i]);
edge[B[i]].push_back(A[i]);
}
dfsb(0, -1);
}
int Boris(int city) {
int ans = 0;
while (city && hub[city] == 0) {
ans += Ask(999-city);
city = p[city];
}
if (hub[city]) {
int pos = hub[city] * 9;
int ac = 0;
for (int i = 0; i < 9; ++i) {
ac += ac;
ac += Ask(--pos);
}
ans += ac;
}
return ans;
}
# | 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... |