Pro.ID10178 TitleFence Loops Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10178 AC3 Submit12 Ratio25.00% 时间&空间限制描述The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only at their endpoints though sometimes more than two fences join together at a given endpoint. The result is a web of fences enclosing his pastures. Farmer Brown wants to start to straighten things out. In particular, he wants to know which of the pastures has the smallest perimeter. Farmer Brown has numbered his fence segments from 1 to N (N = the total number of segments). He knows the following about each fence segment:
Happily, no fence connects to itself. Given a list of fence segments that represents a set of surrounded pastures, write a program to compute the smallest perimeter of any pasture. As an example, consider a pasture arrangement, with fences numbered 1 to 10 that looks like this one (the numbers are fence ID numbers): 1 The pasture with the smallest perimeter is the one that is enclosed by fence segments 2, 7, and 8. 输入Multiple test cases. For each case: Line 1: N (1 ≤ N ≤ 100) Line 2..3×N+1: N sets of three line records:
输出Description The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only at their endpoints though sometimes more than two fences join together at a given endpoint. The result is a web of fences enclosing his pastures. Farmer Brown wants to start to straighten things out. In particular, he wants to know which of the pastures has the smallest perimeter. Farmer Brown has numbered his fence segments from 1 to N (N = the total number of segments). He knows the following about each fence segment:
Happily, no fence connects to itself. Given a list of fence segments that represents a set of surrounded pastures, write a program to compute the smallest perimeter of any pasture. As an example, consider a pasture arrangement, with fences numbered 1 to 10 that looks like this one (the numbers are fence ID numbers): 1 The pasture with the smallest perimeter is the one that is enclosed by fence segments 2, 7, and 8. Input Multiple test cases. For each case: Line 1: N (1 ≤ N ≤ 100) Line 2..3×N+1: N sets of three line records:
Output For each case, output a single line with a single integer that represents the shortest surrounded perimeter. Sample Input 10 Sample Output 12 Source 样例输入10 样例输出12 作者 |