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

26397번 - Tramvaji 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB35292485.714%

문제

One magical night Patrik and Josip were talking about the number 42 and the meaning of life. They were interrupted by the famous lady voice in the tram: The next stop is Jordanovac. Patrik and Josip were distracted by this common sentence and started discussing:

Patrik: It is a very short ride between Joranovac and Maksimir, isn’t it?

Josip: It is, but the ride between Mašićeva and Kvatrić is way shorter.

Patrik: Really? I disagree.

Josip: I wonder, which is the shortest ride between all stations?

Paula, a big public traffic transport, was carefully listening to their conversation. The problem of finding the shortest ride interested her so much that she stayed in the tram longer than she intended just to listen to their conversation.

At each station (except for the first one, when they entered the tram) one of the following two things happened:

  • Patrik said: t minutes have passed since we entered the tram
  • Josip said: From station y to this station t minutes have passed

But before Paula could hear their conclusion about which ride was the shortest, they left the tram! Luckily, Paula remembers all their statements. Now she needs your help! Help her find the duration of the shortest ride and between which two stations the tram drove on that ride.

입력

The first line contains the integer n (2 ≤ n ≤ 1 000), the number of tram stations.

The i-th of the following n − 1 lines contains the information about station i + 1 in one of the following formats:

  • Patrik ti – Duration of the ride between station 1 and station i + 1 is ti (1 ≤ ti ≤ 109)
  • Josip yi ti – Duration of the ride between station y and station i + 1 is ti (yi < i + 1, 1 ≤ ti ≤ 109)

Every station will be in a distinct position.

출력

In one line output three numbers: t, x1, x2, the duration of the shortest ride and the indices of the starting and ending stations of that ride.

If multiple solutions exist, print the one with the smallest indices of the stations.

제한

서브태스크

번호배점제한
112

ti ≤ 1 000

213

Every sentence was said by Patrik.

325

No additional constraints.

예제 입력 1

4
Patrik 3
Patrik 5
Josip 1 7

예제 출력 1

2 2 3

예제 입력 2

2
Josip 1 5

예제 출력 2

5 1 2

예제 입력 3

5
Patrik 4
Josip 2 4
Josip 2 6
Josip 4 2

예제 출력 3

2 3 4

힌트

Clarification of the first example: The tram drove for 3 minutes from the first to the second station, and 5 from the first to the third. We can conclude that from the second to the third station it took 2 minutes, which is the shortest ride.

Clarification of the third example: The ride between the fourth and fifth station is also 2 minutes but, because they have greater indices, only the 2 3 4 solution is accepted.

출처

Contest > Croatian Open Competition in Informatics > COCI 2022/2023 > Contest #2 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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