#P4322. [JSOI2016] 最佳团体

[JSOI2016] 最佳团体

Description

There are NN candidates in the JSOI informatics team, numbered from 11 to NN. For convenience, JYY is numbered 00. Each candidate ii is recommended by a candidate with a smaller number RiR_i. If Ri=0R_i = 0, it means this candidate was picked by JYY himself.

To ensure team harmony, JYY requires that if candidate ii is recruited, then candidate RiR_i must also be in the team. JYY is always in the team. Each candidate has a combat power PiP_i and a recruitment cost SiS_i. JYY wants to recruit KK candidates (excluding JYY) to form the team with the best ratio; that is, maximize the ratio of the total combat power to the total recruitment cost of these KK selected candidates.

Input Format

The first line contains two positive integers KK and NN.

The ii-th of the next NN lines contains three integers SiS_i, PiP_i, RiR_i, indicating candidate ii’s recruitment cost, combat power, and recommender number.

Output Format

Print one real number, the best ratio. The answer should be rounded to three decimal places.

1 2
1000 1 0
1 1000 1
0.001

Hint

For 100%100\% of the testdata, 1KN25001 \le K \le N \le 2500, 0<Si,Pi1040 < S_i, P_i \le 10^4, 0Ri<i0 \le R_i < i.

Translated by ChatGPT 5