#include <bits/stdc++.h>
using namespace std;
vector<int> tree [100001];
vector<int> killed(100001,0);
vector<bool> used(100001,0);
vector<int> dist(100001,0);
int ans=0;
void kills(int v,int p)
{
if(v==p) kills(tree[v][0],v);
if(tree[v].size()==2) for(auto to:tree[v]) if(to!=p) kills(to,v);
if(tree[v].size()>=3) killed[v]++;
return;
}
void goup(int v, int p)
{
if(v==p)
{
for(auto to:tree[v]) if(dist[to]<dist[v]) goup(to,v);
killed[v]=0;
return;
}
if(tree[v].size()==2) for(auto to:tree[v]) if(to!=p) goup(to,v);
if(tree[v].size()>=3)
{
killed[v]++;
return;
}
}
int main()
{
int n,v; cin>>n;
if(n<=5) {cout<<1; return 0;} // Частный случай
tree[1].push_back(0); // Корень тоже должен быть "развилкой"
vector<int> leaves;
for(int i=1;i<n;i++)
{
cin>>v;
tree[v].push_back(i+1);
tree[i+1].push_back(v); //Заполнение графа в том виде, в котором его дают
}
for(int i=1;i<=n;i++)
{
if(tree[i].size()==1 || (i==1 && tree[i].size()==2)) leaves.push_back(i); //Запоминаем все листья
}
queue<int> q; dist[1]=0;
q.push(1); used[1] = true;
while(!q.empty())
{
int qv=q.front(); q.pop();
used[qv]=1;
for(auto to:tree[qv]) //BFS заполняющий вектор dist
{
if(!used[to])
{
q.push(to);
dist[to]=dist[qv]+1;
}
}
}
for(auto l:leaves)
{
kills(l,l); // Первый этап - запросы от каждого листа
}
int maxdist=-1; for(int i=1;i<=n;i++) maxdist=max(maxdist,dist[i]); // Определение максимального "уровня" дерева
int wentup=1;
while(wentup)
{
wentup=0;
for(int l=maxdist;l>0;l--)
{
for(int i=2;i<=n;i++)
{
if(killed[i]==1 && dist[i]==l)
{
goup(i,i); //Этап 2 - поднятие "недошедших" запросов
wentup++;
}
}
}
}
for(int i=1;i<=n;i++) {if(killed[i]>=2) ans++;} //Финальный подсчет "отравленных" развилок
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSB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WF2ZXM7CiAgICBmb3IoaW50IGk9MTtpPG47aSsrKQogICAgewogICAgICAgIGNpbj4+djsKICAgICAgICB0cmVlW3ZdLnB1c2hfYmFjayhpKzEpOwogICAgICAgIHRyZWVbaSsxXS5wdXNoX2JhY2sodik7IC8v0JfQsNC/0L7Qu9C90LXQvdC40LUg0LPRgNCw0YTQsCDQsiDRgtC+0Lwg0LLQuNC00LUsINCyINC60L7RgtC+0YDQvtC8INC10LPQviDQtNCw0Y7RggogICAgfQogCiAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgIHsKICAgICAgICBpZih0cmVlW2ldLnNpemUoKT09MSB8fCAoaT09MSAmJiB0cmVlW2ldLnNpemUoKT09MikpIGxlYXZlcy5wdXNoX2JhY2soaSk7IC8v0JfQsNC/0L7QvNC40L3QsNC10Lwg0LLRgdC1INC70LjRgdGC0YzRjwogICAgfQogCiAgICBxdWV1ZTxpbnQ+IHE7IGRpc3RbMV09MDsKICAgIHEucHVzaCgxKTsgdXNlZFsxXSA9IHRydWU7CiAgICB3aGlsZSghcS5lbXB0eSgpKQogICAgewogICAgICAgIGludCBxdj1xLmZyb250KCk7IHEucG9wKCk7CiAgICAgICAgdXNlZFtxdl09MTsKICAgICAgICBmb3IoYXV0byB0bzp0cmVlW3F2XSkgICAgICAgICAgICAgICAgLy9CRlMg0LfQsNC/0L7Qu9C90Y/RjtGJ0LjQuSDQstC10LrRgtC+0YAgZGlzdAogICAgICAgIHsKICAgICAgICAgICAgaWYoIXVzZWRbdG9dKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBxLnB1c2godG8pOwogICAgICAgICAgICAgICAgZGlzdFt0b109ZGlzdFtxdl0rMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KIAogICAgZm9yKGF1dG8gbDpsZWF2ZXMpCiAgICB7CiAgICAgICAga2lsbHMobCxsKTsgICAgICAgIC8vINCf0LXRgNCy0YvQuSDRjdGC0LDQvyAtINC30LDQv9GA0L7RgdGLINC+0YIg0LrQsNC20LTQvtCz0L4g0LvQuNGB0YLQsAogICAgfQogCiAgICBpbnQgbWF4ZGlzdD0tMTsgZm9yKGludCBpPTE7aTw9bjtpKyspIG1heGRpc3Q9bWF4KG1heGRpc3QsZGlzdFtpXSk7IC8vINCe0L/RgNC10LTQtdC70LXQvdC40LUg0LzQsNC60YHQuNC80LDQu9GM0L3QvtCz0L4gItGD0YDQvtCy0L3RjyIg0LTQtdGA0LXQstCwCiAgICBpbnQgd2VudHVwPTE7CiAgICB3aGlsZSh3ZW50dXApCiAgICB7CiAgICAgICAgd2VudHVwPTA7CiAgICAgICAgZm9yKGludCBsPW1heGRpc3Q7bD4wO2wtLSkKICAgICAgICB7CiAgICAgICAgICAgIGZvcihpbnQgaT0yO2k8PW47aSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihraWxsZWRbaV09PTEgJiYgZGlzdFtpXT09bCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBnb3VwKGksaSk7ICAgICAgICAgICAgICAgICAgICAvL9Ct0YLQsNC/IDIgLSDQv9C+0LTQvdGP0YLQuNC1ICLQvdC10LTQvtGI0LXQtNGI0LjRhSIg0LfQsNC/0YDQvtGB0L7QsgogICAgICAgICAgICAgICAgICAgIHdlbnR1cCsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTE7aTw9bjtpKyspIHtpZihraWxsZWRbaV0+PTIpIGFucysrO30gLy/QpNC40L3QsNC70YzQvdGL0Lkg0L/QvtC00YHRh9C10YIgItC+0YLRgNCw0LLQu9C10L3QvdGL0YUiINGA0LDQt9Cy0LjQu9C+0LoKICAgIGNvdXQ8PGFuczsKICAgIHJldHVybiAwOwp9