408732: GYM103274 J Just Send the Email
Description
Bob just joined a software developing company as a Software Engineer. The organization in this company is simple: each employee is identified by a unique integer ID between $$$1$$$ and $$$N$$$. All the employees $$$i$$$, except for the one with ID equal to $$$1$$$, has a manager denoted by $$$m_i$$$. If $$$m_i$$$ is the manager of $$$i$$$, then $$$i$$$ is considered to be a direct report of $$$m_i$$$.
The employees that are managers of any employee usually are busy with meetings providing feedback of their reports, for that reason some tedious tasks are delegated to the employees that do not have any report. One of those tasks is to reply emails of customers that are complaining about bugs in the systems.
The feedback system works in a strange way. When a customer submits a complaint, a random employee receives an email with the content of the complaint. When a employee receives a complaint email, they reply that email if the employee does not have any direct report. Otherwise, the employee resends the email to their manager or to any of their direct reports. The goal is to minimize the number of people that will receive the email before someone replies to it, so an employee will choose resending the email to their manager or their direct report that minimizes this number assuming that they will also do an optimal election.
Bob is responsible of improving the complaining system, for that reason he wants to measure the impact in the performance of the current system. Help Bob find the expected number of people that will receive the email before replying to it, given that all the employees have the same probability of receiving the complaint email when the customer sends it. Note that the first employee and the last employee that receive the email are also counted.
InputThe input consists of two lines. The first line contains a single integer $$$N$$$ ($$$2 \leq N \leq 10^5$$$), representing the number of employees in the company. The second line contains $$$N-1$$$ integers $$$m_2, m_3, \dots, m_N$$$ ($$$1 \leq m_i < i$$$), where $$$m_i$$$ represents the ID of the manager of employee with ID $$$i$$$.
OutputWe can show that the answer can be represented in the form $$$\frac{p}{q}$$$ such that $$$p$$$ and $$$q$$$ are positive integers and $$$gcd(p,q)=1$$$. Print $$$p*q^{-1}$$$ modulo $$$998244353$$$, where $$$q^{-1}$$$ is the modular multiplicative inverse of $$$q$$$ modulo $$$998244353$$$.
ExamplesInput4 1 2 3Output
499122179Input
6 1 1 3 4 5Output
2Input
5 1 1 1 1Output
598946613Note
The answer represented as fraction for the first example is $$$\frac{5}{2}$$$.
The answer represented as fraction for the second example is $$$\frac{2}{1}$$$.
The answer represented as fraction for the third example is $$$\frac{6}{5}$$$.