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>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
#include "Anyalib.h"
static vector<int>E[600];
static int dep[600];
static int a[600],b[600];
static map<int,int>mp,edge;
int n;
static void dfs(int v,int p,int d){
dep[v]=d;
for(int u:E[v]){
if(u==p)continue;
dfs(u,v,d+1);
}
}
void InitAnya(int N , int A[] , int B[]) {
n=N;
rep(i,n-1){
a[i]=A[i];b[i]=B[i];
E[a[i]].push_back(b[i]);
E[b[i]].push_back(a[i]);
}
dfs(0,-1,0);
int cnt=0;
for(int i=1;i<n;i++){
if(dep[i]%10==0){
mp[i]=cnt;
cnt+=9;
}
}
rep(i,n-1){
if(dep[a[i]]>dep[b[i]])swap(a[i],b[i]);
edge[b[i]]=cnt++;
}
assert(cnt<=1000);
}
static int dist[600];
static int c[600];
static void dfs2(int v,int p,int d){
dist[v]=d;
for(int u:E[v]){
if(u==p)continue;
dfs2(u,v,d+c[u]);
}
}
void Anya(int C[]) {
rep(i,n-1){
if(C[i])c[b[i]]=1;
else c[b[i]]=0;
}
dfs2(0,-1,0);
for(int i=1;i<n;i++){
if(dep[i]%10==0){
int st=mp[i];
rep(j,9){
Save(st+j,dist[i]>>j&1);
}
}
Save(edge[i],c[i]);
}
}
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
#include "Borislib.h"
static vector<int>E[600];
static int dep[600];
static int a[600],b[600];
static map<int,int>mp,edge;
static int par[600];
static void dfs(int v,int p,int d){
dep[v]=d;
for(int u:E[v]){
if(u==p)continue;
dfs(u,v,d+1);
}
}
void InitBoris(int N , int A[] , int B[]) {
rep(i,N-1){
a[i]=A[i];b[i]=B[i];
E[a[i]].push_back(b[i]);
E[b[i]].push_back(a[i]);
}
dfs(0,-1,0);
int cnt=0;
for(int i=1;i<N;i++){
if(dep[i]%10==0){
mp[i]=cnt;
cnt+=9;
}
}
rep(i,N-1){
if(dep[a[i]]>dep[b[i]])swap(a[i],b[i]);
edge[b[i]]=cnt++;
par[b[i]]=a[i];
}
}
int Boris(int city) {
int cnt=0;
while(1){
if(city==0)break;
if(dep[city]%10==0){
int st=mp[city];
rep(i,9){
cnt+=(Ask(st+i)<<i);
}
break;
}
cnt+=Ask(edge[city]);
city=par[city];
}
return cnt;
}
# | 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... |