You are about to change history!
You have recently been informed of unfortunate tests on Nagato by the Am*ricans. Being a responsible citizen, you have decided to take matters into your own hands and stop the Am*ricans from destroying such a beautiful and majestic ship.
The Un*ted St*tes Armed Forces (made up of those Am*ricans, henceforth known as USAF) has members and a hierarchy in which every member (except the President) has exactly one direct superior. Each member of the USAF has a rank. The rank of the President is 1, and each other member's rank is the rank of their direct superior plus 1. For example, if someone's direct superior was the President, their rank would be 2. It is guaranteed that if you follow the chain of superiors of any member of the USAF, you will eventually reach the President.
Your master plan is to immerse the President in anime and manga until he realizes the foolishness of his actions and becomes a weeaboo, after which he will immediately cancel the planned destruction of the Nagato.
You have already gathered a lot of information about the USAF, but you cannot execute your plan yet as some crucial pieces of information are missing. Although you know information such as "these two people form an inferior-superior pair" (that is, one of them is the direct superior of the other), you do not know who is the superior and you do not actually know which person in the USAF (numbered from to ) is the President. And most alarmingly, you do not know how many unique ranks there are among members of the USAF (every rank has a specific etiquette guideline you must learn before you can infiltrate the USAF).
Since the President's number is highly classified, you would like to determine the number of unique ranks in the USAF regardless of which of the members to you assume is the President.
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
The first line of input will have .
The next lines of input will each contain a superior-inferior pair . It is guaranteed that the information corresponds to a valid hierarchy assuming each of the members is the President.
You should output lines. On the line, you should output the number of unique ranks assuming that member is the President.
3 2 1 2 3
3 2 3
Explanation for Sample Output
The following diagrams show the hierarchy of the USAF for each of the three cases where person 1, 2, and 3 are the President. The star next to each person shows their rank.
There are 3 unique ranks: 1, 2, and 3.
There are 2 unique ranks: 1 and 2. Note that both member 1 and member 2 have rank 2, so it's only counted once.
There are 3 unique ranks: 1, 2, and 3. Note that this case is symmetrical to the first case.
Everything appearing in this problem is fictitious. Any resemblance to real countries, people, or battleships is purely coincidental. Nagato
Popular name for this is "tree rerooting" technique. Tutorial