#K33117. Broadcast Message Time
Broadcast Message Time
Broadcast Message Time
You are given an undirected tree with (n) nodes numbered from 1 to (n) and (n-1) edges. Starting from node 1, a message is broadcasted through the tree, where each edge traversal takes 1 unit of time. The task is to compute the minimum time needed to reach every node (i.e., the maximum distance from node 1 to any other node).
In other words, if (d(1, i)) represents the distance from node 1 to node (i), you are to calculate (\max_{1 \le i \le n} d(1,i)).
inputFormat
The input is read from standard input (stdin) and has the following format:
(n) — the number of nodes in the tree.
Next (n-1) lines, each line contains two integers (u) and (v) indicating that there is an edge between nodes (u) and (v).
outputFormat
Print a single integer to standard output (stdout) representing the minimum time required to reach all nodes (i.e., the maximum distance from node 1 to any other node).## sample
5
1 2
1 3
3 4
3 5
2