QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#20831. 牧場施肥

Estadísticas

$N$ 場($2\le N\le2\cdot10^5$),$N-1$ 路成樹,每路 $1$ 秒。初草 $0$,$i$ 每秒 $a_i$($1\le a_i\le10^8$)。John 起 $1$,開車給全部施肥。訪問草 $x$ 需肥 $x$,只首次,時間 $0$。

另給 $T\in\{0,1\}$。

  • $T=0$ 必終 $1$。
  • $T=1$ 任意終點。

求最短時間與在該時間內最少肥。

輸入格式

首行 $N,T$。

每 $i=2..N$ 行 $p_i,a_i$,路連兩場 $p_i,i$,$1\le p_i<i$。

輸出格式

最短時間與最少肥,空格分隔。

範例

輸入格式 1

5 0
1 1
1 2
3 1
3 4

輸出格式 1

8 21

說明

最優路線:

  • 時刻 $1$, 到節點 $3$. 草量 $1 \cdot 2 = 2$; 需肥量 $2$.
  • 時刻 $2$, 到節點 $5$. 草量 $2 \cdot 4 = 8$; 需肥量 $8$.
  • 時刻 $3$, 返回節點 $3$. 已施肥,不再施。
  • 時刻 $4$, 到節點 $4$. 草量 $4 \cdot 1 = 4$; 需肥量 $4$.
  • 時刻 $5$, 返回節點 $3$. 已施肥,不再施。
  • 時刻 $6$, 返回節點 $1$.
  • 時刻 $7$, 到節點 $2$. 草量 $7 \cdot 1 = 7$; 需肥量 $7$.
  • 時刻 $8$, 返回節點 $1$.

耗 $8$,肥 $2+8+4+7=21$。回 $1$ 路線最短可證 $8$,回 $1$ 且 $8$ 的最少肥 $21$。

輸入格式 2

5 1
1 1
1 2
3 1
3 4

輸出格式 2

6 29

說明

最優路線:

  • 時刻 $1$, 到節點 $2$. 草量 $1 \cdot 1 = 1$; 需肥量 $1$.
  • 時刻 $2$, 返回節點 $1$.
  • 時刻 $3$, 到節點 $3$. 草量 $3 \cdot 2 = 6$; 需肥量 $6$.
  • 時刻 $4$, 到節點 $5$. 草量 $4 \cdot 4 = 16$; 需肥量 $16$.
  • 時刻 $5$, 返回節點 $3$. 已施肥,不再施。
  • 時刻 $6$, 到節點 $4$. 草量 $6 \cdot 1 = 6$; 需肥量 $6$.

耗 $6$,肥 $1+6+16+6=29$。所有路線最短 $6$,耗 $6$ 最少肥 $29$。

子任務

  • 測試資料 $3..10$: $T=0$.
  • 測試資料 $11..22$: $T=1$.
  • 測試資料 $3..6$, $11..14$: 無牧場鄰接超過三路。

題目署名:Rohin Garg

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.