#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = l; i <= r; ++i)
#define FOD(i, r, l) for (int i = r; i >= l; --i)
#define ll long long
#define ep emplace_back
#define fi first
#define se second
#define pil pair <int, long long>
#define NAME ""
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 1e5 + 5;
int n, k;
vector <pil> adj[N];
pil dp[N][2];
pil operator + (pil& a, pil b)
{
return make_pair(a.fi + b.fi, a.se + b.se);
}
void dfs(int u, int pa)
{
int m = adj[u].size();
int z = (m - (u != 1));
vector <vector <pil>> f(z + 1, vector <pil> (k + 1, make_pair(0, 0)));
int i = 0;
for (int p = 0; p < m; ++p)
{
ll w = adj[u][p].fi;
int v = adj[u][p].se;
if (v == pa)
continue;
dfs(v, u);
++i;
f[i][0] = f[i - 1][0] + dp[v][0];
FOR(j, 1, k)
{
f[i][j] = max(f[i][j - 1], f[i - 1][j] + dp[v][0]);
pil tmp = {1, -w};
tmp = tmp + f[i - 1][j - 1];
tmp = tmp + dp[v][1];
f[i][j] = max(f[i][j], tmp);
}
}
dp[u][0] = f[z][k];
dp[u][1] = f[z][k - 1];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen(NAME".INP", "r"))
{
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin >> n >> k;
FOR(i, 2, n)
{
int v;
ll w;
cin >> v >> w;
adj[v].ep(w, i);
adj[i].ep(w, v);
}
dfs(1, 1);
cout << dp[1][0].fi << ' ' << -dp[1][0].se;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRk9SKGksIGwsIHIpIGZvciAoaW50IGkgPSBsOyBpIDw9IHI7ICsraSkKI2RlZmluZSBGT0QoaSwgciwgbCkgZm9yIChpbnQgaSA9IHI7IGkgPj0gbDsgLS1pKQojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGVwIGVtcGxhY2VfYmFjawojZGVmaW5lIGZpIGZpcnN0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gIHRtcCA9IHRtcCArIGRwW3ZdWzFdOwogICAgICAgICAgICBmW2ldW2pdID0gbWF4KGZbaV1bal0sIHRtcCk7CiAgICAgICAgfQogICAgfQogICAgZHBbdV1bMF0gPSBmW3pdW2tdOwogICAgZHBbdV1bMV0gPSBmW3pdW2sgLSAxXTsKfQoKc2lnbmVkIG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBpZiAoZm9wZW4oTkFNRSIuSU5QIiwgInIiKSkKICAgIHsKICAgICAgICBmcmVvcGVuKE5BTUUiLklOUCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oTkFNRSIuT1VUIiwgInciLCBzdGRvdXQpOwogICAgfQogICAgY2luID4+IG4gPj4gazsKICAgIEZPUihpLCAyLCBuKQogICAgewogICAgICAgIGludCB2OwogICAgICAgIGxsIHc7CiAgICAgICAgY2luID4+IHYgPj4gdzsKICAgICAgICBhZGpbdl0uZXAodywgaSk7CiAgICAgICAgYWRqW2ldLmVwKHcsIHYpOwogICAgfQogICAgZGZzKDEsIDEpOwogICAgY291dCA8PCBkcFsxXVswXS5maSA8PCAnICcgPDwgLWRwWzFdWzBdLnNlOwogICAgcmV0dXJuIDA7Cn0=