#P9735. [COCI 2022/2023 #2] Tramvaji

    ID: 10997 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>模拟2022COCI(克罗地亚)

[COCI 2022/2023 #2] Tramvaji

Problem Description

Patrik and Josip are riding a tram. They ride for a total of nn stops.

At every stop after the boarding stop, exactly one of the following events happens upon arrival:

  • Patrik says: tt minutes have passed since we boarded.

  • Josip says: It took tt minutes to get here from stop yy.

Now, based on this information, find which two stops have the shortest travel time between them, and output that time.

Input Format

The input has nn lines.

The first line contains an integer nn (2n10002\le n\le1000), the number of stops.

The next n1n-1 lines describe the event that happened at stop i+1i+1 on line ii:

  • Type 1: Patrik ti\texttt{Patrik } t_i (1ti1091\le t_i\le10^9).

  • Type 2: Josip yi ti\texttt{Josip } y_i\texttt{ }t_i (yi<i+1y_i < i + 1, 1ti1091\le t_i\le10^9).

Each stop is at a different position.

Output Format

Output one line with three integers tt, x1x_1, x2x_2, representing the shortest time, and the start and end stops that achieve this shortest time.

If there are multiple answers, output the lexicographically smallest one.

4
Patrik 3
Patrik 5
Josip 1 7
2 2 3
2
Josip 1 5
5 1 2
5
Patrik 4
Josip 2 4
Josip 2 6
Josip 4 2
2 3 4

Hint

This problem uses bundled testdata.

Subtask\text{Subtask} Score Special properties
11 1212 ti1000t_i \le 1000
22 1313 Only Patrik\texttt{Patrik} events
33 2525 None

The full score for this problem is 5050 points.

Translated by ChatGPT 5