K-th mean path

2.5

2 votes
Data Structures, Fenwick Tree, Fenwick tree, Hard
Problem

Given a weighted rooted tree with n vertices. Let's call simple path from u to v vertical iff uv and u is on simple path from root to v. The weight of the path is a sum of weights for all edges in the path. The mean weight of the path is a weight of the path divided by number of edges in it. Calculate mean weight of each vertical path, sort them and print k-th value in sorted order.

Input Format

The first line of input contains two integers n and k (2n106). It is guaranteed that there are at least k vertical paths in the given tree.

Next n1 lines contain description of edges u,v,c (1u,vn,1c105).

The root of the tree is vertex 1.

Output Format

Print the k-th minimal mean weight as an irreducible fraction.

Scoring

n100  10 points

n2000  10 points

n15000, k105  15 points

n15000  10 points

n105  25 points

n106,k500  30 points

Time Limit: 5
Memory Limit: 512
Source Limit:
Explanation

These are the vertical paths in the given tree: 12, 123, 124, 15, 23 and 24

Mean weights of the paths:

f(12)=2

f(123)=42=2

f(124)=52

f(15)=2

f(23)=2

f(24)=3

So, if we sort these values, we get: 2,2,2,2,52,3

Editor Image

?