Gastronomic Event
Time limit2sMemory limit2048 MB
Assign ratings 1 to n to the rooms of a tree so that the number of edge-following paths with increasing ratings is maximized, and print that maximum.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
The SWERC organizers want to hold a gastronomic event.
The event takes place in a building with rooms connected by corridors, where each corridor joins two rooms and it is possible to go from any room to any other room.
In each room, you must set up a tasting of a typical Italian dish. There are dishes, rated from to by quality, where is the best rating. The dishes have distinct ratings.
Assign the dishes to the rooms so that the number of pleasing tours is maximal. A pleasing tour is a nonempty sequence of rooms such that:
- Each room in the sequence is connected to the next room in the sequence by a corridor.
- The dish ratings along the sequence are increasing.
If you assign the dishes optimally, what is the maximum number of pleasing tours?
Input
The first line contains an integer (), the number of rooms.
The second line contains integers (). Each means there is a corridor between room and room . It is guaranteed that the building lets you go from any room to any other room.
Output
Print the maximum number of pleasing tours.