#include "graph.h"
#include <vector>
#include <cmath>
int N = 1;
int fa[207], tofa[207], fato[207];
std::vector<std::pair<std::pair<int, int>, int>> E[207];
void dfs_tree(int u) {
int d = NumberOfRoads();
for (int i = 1; i <= d; ++i) {
Move(i, 2);
int c = Color();
if (c == 1) {
int v = ++N;
fa[v] = u, tofa[v] = LastRoad(), fato[v] = i;
dfs_tree(v);
Move(tofa[v], 3);
} else if (c == 2) {
if (i != tofa[u]) {
E[u].push_back({{i, LastRoad()}, 0});
}
Move(LastRoad(), 2);
} else {
Move(LastRoad(), 3);
}
}
}
void dfs_calc(int u, int g) {
int d = NumberOfRoads();
for (int i = 1; i <= N; ++i) {
if (fa[i] == u) {
Move(fato[i], (u / int(std::pow(3, g))) % 3 + 1);
dfs_calc(i, g);
Move(tofa[i], (i / int(std::pow(3, g))) % 3 + 1);
}
}
for (auto& [fb, v] : E[u]) {
Move(fb.first, (u / int(std::pow(3, g))) % 3 + 1);
int c = Color();
v += (c - 1) * int(std::pow(3, g));
Move(fb.second, c);
}
}
int dis[207][207];
void Inspect(int R) {
dfs_tree(1);
dfs_calc(1, 0);
dfs_calc(1, 1);
dfs_calc(1, 2);
dfs_calc(1, 3);
dfs_calc(1, 4);
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
dis[i][j] = +0x3b9aca00;
}
dis[i][i] = 0;
}
for (int i = 2; i <= N; ++i) {
dis[i][fa[i]] = dis[fa[i]][i] = 1;
for (auto [fb, v] : E[i]) {
dis[i][v] = dis[v][i] = 1;
}
}
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
for (int k = 1; k <= N; ++k) {
dis[j][k] = std::min(dis[j][k], dis[j][i] + dis[i][k]);
}
}
}
for (int k = 1; k <= R; ++k) {
int ans = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j < i; ++j) {
if (dis[i][j] == k) {
++ans;
}
}
}
Answer(k, ans);
}
}