#P4410. [HNOI2009] 无归岛

    ID: 3296 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2009各省省选湖南仙人掌

[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 aa and bb on the same island, there exists exactly one creature cc who is a friend of both aa and bb. 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 nn and mm separated by a space, denoting the number of creatures in Neverland and the number of friend pairs.

Each of the next mm lines describes a friend pair. Specifically, each line contains two integers aa and bb separated by a space, indicating that creature aa and creature bb are friends (each friend pair appears exactly once). The (m+2)(m+2)-th line contains nn integers separated by spaces, where the ii-th integer denotes the battle power AiA_i of creature ii.

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 11 is on island 11, creature 22 is on island 22, creatures 33, 55, 66 are on island 33, and creature 44 is on island 44.

Constraints: 4n1000004 \le n \le 100000, 1a,bn1 \le a, b \le n, 1m2000001 \le m \le 200000, 1000Ai1000-1000 \le A_i \le 1000.

Translated by ChatGPT 5