This page is still under construction.

Parts of this page are still being built. What you see may change.

Optical Communication Channels

Time limit1sMemory limit512 MB

Summary
Given a rooted tree where each node has at most k chosen edges, pick the maximum number of edges forming a degree-bounded subgraph, and among those the minimum total weight.
Level

Hard8 of 10

Topics
Tree, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Flatland has nn cities numbered from 1 to nn. City 1 is the capital. Each city has one connection center, and centers can be linked to other centers by wired communication channels. Any two cities are joined by exactly one route through the channels, so the network is a tree. For a city ii with i>1i > 1, let pip_i be the first city on the route from city ii to the capital.

The network is being upgraded, and some wired channels will be replaced with newer optical ones. An optical channel can only be installed in place of an existing wired channel. Replacing the channel that connects city ii with city pip_i costs wiw_i. Because of technology limits, each connection center can be connected by optical channels to at most kk other centers.

The Flatland ministry wants a plan that makes the optical network as connected as possible, so it must upgrade as many channels as it can. Among plans with the same number of upgraded channels, the total cost should be minimal.

Help the ministry choose the channels to upgrade.

Input

The first line contains two integers nn and kk (2≤n≤1052 \le n \le 10^5, 1≤k≤1001 \le k \le 100). Each of the next n−1n - 1 lines contains two integers pip_i and wiw_i (1≤pi≤i1 \le p_i \le i, 0≤wi≤1090 \le w_i \le 10^9). The (i−1)(i-1)-th of these lines describes city ii.

Output

Print two integers cntcnt and costcost: the maximum number of channels that can be upgraded, and the minimum cost of upgrading that many channels.

Hint

In the first example, the network before and after the upgrade is shown in the figure below. Upgraded channels are drawn as thick lines. The maximum number of channels that can be upgraded is 4. The upgrade cost of every channel is 0, so costs are not shown.

There are other valid solutions that upgrade 4 channels.

In the second example, the network before and after the upgrade is shown below. Upgraded channels are thick lines, and the cost of each channel is written next to it. The maximum number of upgraded channels is 6, and the total cost of the optimal solution is 27.

Examples2

  1. Example 1

    Input
    8 2
    1 0
    1 0
    1 0
    2 0
    2 0
    2 0
    1 0
    
    Expected output
    4 0
    
  2. Example 2

    Input
    8 3
    1 5
    1 2
    1 4
    2 6
    2 7
    2 2
    1 6
    
    Expected output
    6 27