#P4410. [HNOI2009] 无归岛
[HNOI2009] 无归岛
Description
Neverland is a magical place made up of several islands arranged in a ring. Each island is home to a distinct species, and creatures live on these islands.
All these species share a common social habit: for any two creatures on the same island, they have exactly one common friend. That is, for any two creatures and on the same island, there exists exactly one creature who is a friend of both and . Of course, some islands may have only one creature living alone.
There is also communication between islands. Specifically, each island chooses the smartest creature as its representative, and this representative becomes friends with the representatives of its two neighboring islands.
Unfortunately, World A plans to invade Neverland. As its guardian, Lostmonkey wants to know Neverland’s fighting power in a relatively unfavorable situation. Fighting alongside friends increases ability, so Lostmonkey wants to know the maximum fighting power without selecting any pair of friends. In other words, select some creatures such that no two selected creatures are friends, and maximize the sum of their battle power.
Input Format
The first line contains two integers and separated by a space, denoting the number of creatures in Neverland and the number of friend pairs.
Each of the next lines describes a friend pair. Specifically, each line contains two integers and separated by a space, indicating that creature and creature are friends (each friend pair appears exactly once). The -th line contains integers separated by spaces, where the -th integer denotes the battle power of creature .
Output Format
Output a single integer, the maximum total battle power satisfying the condition.
6 7
1 2
2 3
3 4
4 1
3 6
3 5
5 6
20 10 30 15 20 10
50
Hint
Sample explanation: There are four islands. Creature is on island , creature is on island , creatures , , are on island , and creature is on island .
Constraints: , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号