#619
Unrated
Fertilizing Pastures
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

There are NN pastures (2N21052 \le N \le 2\cdot 10^5), connected by N1N-1 roads, such that they form a tree. Every road takes 1 second to cross. Each pasture starts out with 0 grass, and the iith pasture's grass grows at a rate of aia_i (1ai1081\le a_i\le 10^8) units per second. Farmer John is in pasture 1 at the start, and needs to drive around and fertilize the grass in every pasture. If he visits a pasture with xx units of grass, it will need xx amount of fertilizer. A pasture only needs to be fertilized the first time it is visited, and fertilizing a pasture takes 0 time.

The input contains an additional parameter T{0,1}T\in \{0,1\}.

If T=0T=0, Farmer John must end at pasture 1.If T=1T=1, Farmer John may end at any pasture.

Compute the minimum amount of time it will take to fertilize every pasture and the minimum amount of fertilizer needed to finish in that amount of time.

입력

The first line contains NN and TT.

Then for each ii from 22 to NN, there is a line containing pip_i and aia_i, meaning that there is a road connecting pastures pip_i and ii. It is guaranteed that 1pi<i1\le p_i<i.

출력

The minimum amount of time and the minimum amount of fertilizer, separated by spaces.

예제 입력 1

5 0
1 1
1 2
3 1
3 4

예제 출력 1

8 21

예제 입력 2

5 1
1 1
1 2
3 1
3 4

예제 출력 2

6 29

점수

Inputs 3-10: T=0T=0Inputs 11-22: T=1T=1Inputs 3-6 and 11-14: No pasture is adjacent to more than three roads.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.