当前位置: 代码迷 >> 综合 >> Two Paths(翻译)
  详细解决方案

Two Paths(翻译)

热度:97   发布时间:2023-12-05 14:31:37.0

2022.2.14

题目网址:

https://codeforces.com/contest/14/problem/D

原题:

Two Paths

 2000ms  65536K

描述:

As you know, Bob's brother lives in Flatland. 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, where Bob's brother works, 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?≤?200), 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 ai,?bi (1?≤?ai,?bi?≤?n).

输出:

Output the maximum possible profit.

翻译:

描述:

据你所知,鲍勃的兄弟住在平原地区。在这里的平原有n座城市,由n-1条双向道路连接。这些城市编号从1到n。你能通过沿马路移动从一个城市到另一个城市。

《两条路》公司,也就是鲍勃兄弟工作的地方,已经赢得了修理平原两条路径的招标。一条路径是由道路连接的不同城市的一个次序。这个公司被允许去自主选择要修的道路。它们必须满足的唯一条件是这两条路径不应该交叉(也就是不应该有相同的城市)。

我们知道《两条路》公司将得到的盈利等同于这两条路径长度的乘积。如果每条路径的长度等于1,一条路的长度等于在这条路径里的路的数量。找到这个公司的最大可能的盈利。

输入:

第一行包含一个整数n(2<=n<=200),这里的n是在这个区域的城市的数量。接下来n-1行包含这些路的信息。每行包含城市的一对数,是这条路的ai,bi(1<=ai,bi<=n)。

输出:

输出最大可能盈利。

  相关解决方案