#P15182. [SWERC 2021] Gastronomic Event
[SWERC 2021] Gastronomic Event
题目描述
SWERC organizers want to hold a gastronomic event.
The location of the event is a building with rooms connected by corridors (each corridor connects two rooms) so that it is possible to go from any room to any other room.
In each room you have to set up the tasting of a typical Italian dish. You can choose from typical Italian dishes rated from to depending on how good they are ( is the best possible rating). The dishes have distinct ratings.
You want to assign the dishes to the rooms so that the number of pleasing tours is maximal. A pleasing tour is a nonempty sequence of rooms so that:
- Each room in the sequence is connected to the next one in the sequence by a corridor.
- The ratings of the dishes in the rooms (in the order given by the sequence) are increasing.
If you assign the dishes optimally, what is the maximum number of pleasing tours?
输入格式
The first line contains an integer ( ) — the number of rooms.
The second line contains integers ( ). Each indicates that there is a corridor between room and room . It is guaranteed that the building has the property that it is possible to go from any room to any other room.
输出格式
Print the maximum number of pleasing tours.
5
1 2 2 2
13
10
1 2 3 4 3 2 7 8 7
47
提示
In the first sample, it is optimal to place the dish with rating in room , the dish with rating in room , the dish with rating in room , the dish with rating in room and the dish with rating in room .
All the possible pleasing tours are: , , , , , , , , , , , , .
There are also other ways to assign the dishes to the rooms so that there are pleasing tours.