AlgoUniversity
  • Go Back
Discussion
Message Passing :

Author

Shikhar Mehrotra

Difficulty Level : Medium

Submissions : 921

Asked In : Slice

Marks :20

: 8 | : 1

You are in a corporate and you need to communicate about a strategic mission in-person to all the people in your company. This information can NOT be broadcasted so you have to tell it to each person in a $$$1-1$$$ session. It takes $$$1$$$ hour to communicate the information from one person to another. At any given point of time, a manager can communicate this vital strategic information to one of his/her direct reports. Let us say we have the following reporting structure: Find out the minimum number of hours in which the information can be communicated to all the members of the organization. Assuming that node $$$1$$$ has the information initially

Input

The first line contains a single integer $$$1\le N \le 10^{5}$$$.

Following $$$N−1$$$ lines contains two space separated integers $$$u$$$ and $$$v$$$ which denotes $$$u$$$ and $$$v$$$ are connected by an edge

Output

Output the minimum number of hours in which the information can be communicated to all the members of the organization if assuming that node $$$1$$$ has information initially.

Example

Input
17
1 2
1 3
1 4
1 5
1 6
1 7
2 8
2 9
2 10
8 11
8 12
5 13
5 14
13 15
14 16
7 17
Output
6

Note

In the given tree,

At the end of $$$1$$$ hour , $$$1$$$ will pass the info to $$$2$$$.

At the end of $$$2$$$ hour , $$$1$$$ will pass the info to $$$5$$$ , $$$2$$$ will pass the info to $$$8$$$.

At the end of $$$3$$$ hour , $$$1$$$ will pass the info to $$$7$$$ , $$$2$$$ will pass the info to $$$9$$$, $$$5$$$ will pass the info to $$$13$$$, $$$8$$$ will pass info to $$$11$$$.

... and so on.

Non circled numbers represent time to convey the information to respective nodes.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.