#include "Anyalib.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
void Save(int place, int bit);
const int M = 10, MAXN = 500;
vector<int> v1[M];
vector<pair<int, int> > adj1[MAXN];
vector<int> stoa1, stob1;
int dep1[MAXN];
int ans1[MAXN];
void InitAnya(int N, std::vector<int> A, std::vector<int> B) {
stoa1 = A;
stob1 = B;
}
void dfs1(int node, int prv) {
dep1[node] = (prv == -1 ? 0 : dep1[prv] + 1);
if(prv != -1) v1[dep1[node] % M].push_back(node);
for(pair<int, int> x: adj1[node]) {
if(x.first != prv) {
ans1[x.first] = ans1[node] + x.second;
dfs1(x.first, node);
}
}
}
void Anya(std::vector<int> C) {
int N = C.size() + 1;
for(int i=0; i<N; i++) {
adj1[i].clear();
}
for(int i=0; i<M; i++) {
v1[i].clear();
}
for(int i=0; i<N-1; i++) {
adj1[stoa1[i]].push_back({stob1[i], C[i]});
adj1[stob1[i]].push_back({stoa1[i], C[i]});
}
dfs1(0, -1);
int minsize = 1e9, id;
for(int i=0; i<M; i++) {
if(v1[i].size() < minsize) {
minsize = v1[i].size();
id = i;
}
}
for(int i=0; i<v1[id].size(); i++) {
for(int j=0; j<9; j++) {
int bruh = ans1[v1[id][i]] & (1 << j);
if(bruh > 0) bruh = 1;
Save(i * 9 + j, bruh);
}
}
for(int i=500; i<500+N-1; i++) {
Save(i, C[i-500]);
}
}
#include "Borislib.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int Ask(int place);
const int M = 10, MAXN = 500;
vector<int> v2[M];
vector<int> adj2[MAXN];
vector<int> stoa2, stob2;
int dep2[MAXN];
int par2[MAXN];
map<pair<int,int>,int> idedge;
void dfs2(int node, int prv) {
dep2[node] = (prv == -1 ? 0 : dep2[prv] + 1);
if(prv != -1) v2[dep2[node] % M].push_back(node);
par2[node] = prv;
for(int x: adj2[node]) {
if(x != prv) {
dfs2(x, node);
}
}
}
int minsize, id;
void InitBoris(int N, std::vector<int> A, std::vector<int> B) {
for(int i=0; i<N; i++) {
adj2[i].clear();
}
for(int i=0; i<M; i++) {
v2[i].clear();
}
idedge.clear();
for(int i=0; i<N-1; i++) {
idedge[{A[i], B[i]}] = idedge[{B[i], A[i]}] = i;
adj2[A[i]].push_back(B[i]);
adj2[B[i]].push_back(A[i]);
}
stoa2 = A;
stob2 = B;
dfs2(0, -1);
minsize = 1e9;
for(int i=0; i<M; i++) {
if(v2[i].size() < minsize) {
minsize = v2[i].size();
id = i;
}
}
}
int Boris(int city) {
int ans = 0;
while(dep2[city] % M != id) {
if(city == 0) return ans;
ans += Ask(500 + idedge[{city, par2[city]}]);
city = par2[city];
}
for(int i=0; i<v2[id].size(); i++) {
if(v2[id][i] == city) {
int add = 0;
for(int j=i*9+8; j>=i*9; j--) {
add = add * 2 + Ask(j);
}
ans += add;
}
}
return ans;
}
Compilation message
Anya.cpp: In function 'void Anya(std::vector<int>)':
Anya.cpp:50:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | if(v1[i].size() < minsize) {
| ~~~~~~~~~~~~~^~~~~~~~~
Anya.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0; i<v1[id].size(); i++) {
| ~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccE8i5bx.o: in function `main':
grader_anya.cpp:(.text.startup+0xde): undefined reference to `InitAnya(int, int*, int*)'
/usr/bin/ld: grader_anya.cpp:(.text.startup+0x1bf): undefined reference to `Anya(int*)'
collect2: error: ld returned 1 exit status
Boris.cpp: In function 'void InitBoris(int, std::vector<int>, std::vector<int>)':
Boris.cpp:52:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if(v2[i].size() < minsize) {
| ~~~~~~~~~~~~~^~~~~~~~~
Boris.cpp: In function 'int Boris(int)':
Boris.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0; i<v2[id].size(); i++) {
| ~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccXCZJWg.o: in function `main':
grader_boris.cpp:(.text.startup+0x17d): undefined reference to `InitBoris(int, int*, int*)'
collect2: error: ld returned 1 exit status