In a tree of employees with speeds, pair each node with at most one neighbor on the parent-child edge, maximizing team count then average team speed.
Medium7TreeDynamic programmingGreedyNo attempts yetTime limit2sMemory limit512 MBYour employer hosts a company picnic every year. One of the events is a three-legged race, where two runners form a team, stand side by side, tie the legs between them together and run. Running that way is harder, so a team runs at the smaller of the two running speeds. For example, if Mildred runs 4.4 meters per second and Ken runs 4.0 meters per second, their team runs 4.0 meters per second.
To improve morale, every team is made of an employee and the supervisor that employee reports to directly. In the organization chart below, Mildred can team up with Ken (4.0 meters per second) or with Zack (4.2 meters per second), but Mildred cannot team up with Barbara.

Figure 1: the organization chart of the first example input.
Given the organization chart, form as many teams as you can. Each employee belongs to at most one team. The race should be exciting, so among all ways to form that many teams you must pair the runners so that the average team speed is as large as possible. In the chart above you can build four teams by pairing Mildred with Ken, Zack with Tina, Wilbur with Virgil and Rose with Seth. Pairing Rose with Barbara instead of Seth still gives four teams and a larger average speed.
The first line contains the total number of employees n (2≤n≤1000). Each of the next n lines describes one employee. A line holds three space separated values: the name of the employee, a real number giving the running speed in meters per second, and the name of that employee's immediate supervisor in the organization chart.
The organization chart always forms a tree with the CEO at the root. The CEO reports to nobody, so the supervisor field of that line is "CEO", and no employee is named CEO. For every other employee the supervisor is the name of an employee listed on another line. All names are distinct and consist of 1 to 12 upper and lower case letters a to z. Every running speed is between 2.2 and 5.3 meters per second and has at most 3 digits after the decimal point.
Print the largest number of teams you can form and the maximum average team speed for that number of teams, separated by one space, on a single line.
Print the average speed with exactly 8 digits after the decimal point. Round a value that falls exactly halfway upward.