#P2451. [SDOI2005] 遗传代码
[SDOI2005] 遗传代码
Description
The abstract genetic code of a primitivus (Primitivus loop) is a sequence of natural numbers . A feature of a primitivus is an ordered pair , meaning that appear consecutively in . That is, there exists an such that , . In the genetic code of a primitivus, there is no feature.
Task
Write a program to:
- Read the list of features from a text file.
- Compute the length of the shortest genetic code that contains all the given features.
- Output the answer.
Input Format
The first line contains a positive integer , which is the number of distinct features of the primitivus.
Then follow lines. Each line contains two numbers and separated by a space. The pair is a feature of the primitivus. In the input file, features do not repeat.
Output Format
Output a single line containing one integer, which is the length of the shortest genetic code of the primitivus.
12
2 3
3 9
9 6
8 5
5 7
7 6
4 5
5 1
1 4
4 2
2 8
8 6
15
Hint
Sample Explanation
One shortest genetic code that satisfies all the features given in the input is: .
Constraints
For all data, , .
Translated by ChatGPT 5
京公网安备 11011102002149号