TWOPATHS - Two Paths
In Flatland there are N cities, connected by N-1 two-way roads. The cities are numbered from 1 to N. You can get from one city to another moving along the roads.
The "Two Paths" company, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities).
It is known that the profit, the "Two Paths" company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company.
The first line contains an integer N (2 ≤ N ≤ 100000), where N is the amount of cities in the country. The following N-1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road a and b (1 ≤ a, b ≤ N)
Output the maximum possible profit.
I would just emphasize that you can reach any city from any other city, directly or indirectly(via route going through other cities). I don't think that is clear from the text of the problem
why time limit is so strict :(((((
Last edit: 2018-10-08 03:07:32
strict time limit :/
Last edit: 2012-05-01 05:29:39
do anyone can give another test case
If another sample is provided I won't have the 1st WA...