Logo
(追記) (追記ここまで)

8067번 - Primitivus 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 128 MB2810945.000%

문제

A genetic code of the abstract primitivus (Primitivus recurencis) is a series of natural numbers K=(a1,…,an). A feature of primitivus we call each ordered pair of numbers (l,r), which appears successively in the genetic code, i.e. there exists such i that l=ai, r=ai +1. There are no (p,p) features in a primitivus' genetic code.

Write a program which:

  • reads the list of the features from the standard input,
  • computes the length of the shortest genetic code having given features,
  • writes the results to the standard output.

입력

In the first line of the standard input one positive integer number n is written. It is the number of different features of the primitivus. In each of the following n lines there is a pair of natural numbers l and r separated by a single space, 1 ≤ l ≤ 1000, 1 ≤ r ≤ 1000. A pair (l,r) is one of the primitivus' features. The features do not repeat in the input file.

출력

Your program should write, in the first and only line of the standard output, exactly one integer number equal to the length of the shortest genetic code of the primitivus, comprising the features from the input.

제한

예제 입력 1

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

예제 출력 1

15

힌트

All the features from the sample input are written in the following genetic code: (8, 5, 1, 4, 2, 3, 9, 6, 4, 5, 7, 6, 2, 8, 6).

출처

Olympiad > Polish Olympiad in Informatics > POI 1998/1999 > Stage 3 5번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /