#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin >> m;
const int N = 2 * m + 100;
const int h = 32 - __builtin_clz(N);
vector<vector<int>> pr(N, vector<int>(h));
vector<int> depth(N);
auto add = [&](int p, int x) { // p 为 x 的父节点
depth[x] = depth[p] + 1;
pr[x][0] = p;
for (int j = 0; j < h; j++) {
if (pr[x][j] == -1) {
pr[x][j + 1] = -1;
} else {
pr[x][j + 1] = pr[pr[x][j]][j];
}
}
};
auto lca = [&](int x, int y) {
if (depth[x] < depth[y]) {
swap(x, y);
}
int d = depth[x] - depth[y];
for (int j = 0; j < h; j++) {
if ((d >> j) & 1) {
x = pr[x][j];
}
}
if (x == y) {
return x;
}
for (int j = h - 1; j >= 0; j--) {
if (pr[x][j] != -1 && pr[x][j] != pr[y][j]) {
x = pr[x][j];
y = pr[y][j];
}
}
return pr[x][0];
};
int diam = 2;
int dx = 1, dy = 2;
add(0, 1); add(0, 2); add(0, 3);
auto update = [&](int x, int y) {
int z = lca(x, y);
int dist = depth[x] + depth[y] - 2 * depth[z];
if (dist > diam) {
diam = dist;
dx = x;
dy = y;
}
};
for (int i = 0, n = 4; i < m; i++, n += 2) {
int x;
cin >> x;
x--;
add(x, n); add(x, n + 1);
update(dx, n); update(dy, n); // 把新插入的节点和原来的直径起点终点组合一下
cout << diam << '\n';
}
cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogIGNpbi50aWUobnVsbHB0cik7CiAgaW50IG07CiAgY2luID4+IG07CiAgY29uc3QgaW50IE4gPSAyICogbSArIDEwMDsKICBjb25zdCBpbnQgaCA9IDMyIC0gX19idWlsdGluX2NseihOKTsKICB2ZWN0b3I8dmVjdG9yPGludD4+IHByKE4sIHZlY3RvcjxpbnQ+KGgpKTsKICB2ZWN0b3I8aW50PiBkZXB0aChOKTsKICBhdXRvIGFkZCA9IFsmXShpbnQgcCwgaW50IHgpIHsgLy8gcCDkuLogeCDnmoTniLboioLngrkKICAgIGRlcHRoW3hdID0gZGVwdGhbcF0gKyAxOwogICAgcHJbeF1bMF0gPSBwOwogICAgZm9yIChpbnQgaiA9IDA7IGogPCBoOyBqKyspIHsKICAgICAgaWYgKHByW3hdW2pdID09IC0xKSB7CiAgICAgICAgcHJbeF1baiArIDFdID0gLTE7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcHJbeF1baiArIDFdID0gcHJbcHJbeF1bal1dW2pdOwogICAgICB9CiAgICB9CiAgfTsKICBhdXRvIGxjYSA9IFsmXShpbnQgeCwgaW50IHkpIHsKICAgIGlmIChkZXB0aFt4XSA8IGRlcHRoW3ldKSB7CiAgICAgIHN3YXAoeCwgeSk7CiAgICB9CiAgICBpbnQgZCA9IGRlcHRoW3hdIC0gZGVwdGhbeV07CiAgICBmb3IgKGludCBqID0gMDsgaiA8IGg7IGorKykgewogICAgICBpZiAoKGQgPj4gaikgJiAxKSB7CiAgICAgICAgeCA9IHByW3hdW2pdOwogICAgICB9CiAgICB9CiAgICBpZiAoeCA9PSB5KSB7CiAgICAgIHJldHVybiB4OwogICAgfQogICAgZm9yIChpbnQgaiA9IGggLSAxOyBqID49IDA7IGotLSkgewogICAgICBpZiAocHJbeF1bal0gIT0gLTEgJiYgcHJbeF1bal0gIT0gcHJbeV1bal0pIHsKICAgICAgICB4ID0gcHJbeF1bal07CiAgICAgICAgeSA9IHByW3ldW2pdOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gcHJbeF1bMF07CiAgfTsKICBpbnQgZGlhbSA9IDI7CiAgaW50IGR4ID0gMSwgZHkgPSAyOwogIGFkZCgwLCAxKTsgYWRkKDAsIDIpOyBhZGQoMCwgMyk7CiAgYXV0byB1cGRhdGUgPSBbJl0oaW50IHgsIGludCB5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