#P1711B. Party
Party
Party
题面翻译
一个俱乐部计划举办一次聚会,并邀请 名会员中的一些人。 名成员分别由数字 表示。如果成员 没有被邀请,团队将获得 的不快乐值。
名成员中有 对好友。按照惯例,如果邀请了一对好友,他们会在聚会上分享蛋糕。被吃掉蛋糕的总数将等于两名成员都被邀请的好友的对数。
然而,俱乐部的烤箱一次只能烤两个蛋糕。因此,俱乐部要求吃掉的蛋糕总数是偶数。
聚会的最低的总不快乐值是多少,考虑到被吃掉的蛋糕总数为偶数的约束条件?
题目描述
A club plans to hold a party and will invite some of its members. The members are identified by the numbers . If member is not invited, the party will gain an unhappiness value of .
There are pairs of friends among the members. As per tradition, if both people from a friend pair are invited, they will share a cake at the party. The total number of cakes eaten will be equal to the number of pairs of friends such that both members have been invited.
However, the club's oven can only cook two cakes at a time. So, the club demands that the total number of cakes eaten is an even number.
What is the minimum possible total unhappiness value of the party, respecting the constraint that the total number of cakes eaten is even?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases ( ). The description of the test cases follows.
The first line of each test case contains two integers and ( , ) — the number of club members and pairs of friends.
The second line of each test case contains integers ( ) — the unhappiness value array.
Each of the next lines contains two integers and ( , ) indicating that and are friends. Each unordered pair appears at most once in each test case.
It is guaranteed that both the sum of and the sum of over all test cases do not exceed .
输出格式
For each test case, print a line containing a single integer – the minimum possible unhappiness value of a valid party.
样例 #1
样例输入 #1
4
1 0
1
3 1
2 1 3
1 3
5 5
1 2 3 4 5
1 2
1 3
1 4
1 5
2 3
5 5
1 1 1 1 1
1 2
2 3
3 4
4 5
5 1
样例输出 #1
0
2
3
2
提示
In the first test case, all members can be invited. So the unhappiness value is .
In the second test case, the following options are possible:
- invite and ( cakes eaten, unhappiness value equal to );
- invite and ( cakes eaten, unhappiness value equal to );
- invite only ( cakes eaten, unhappiness value equal to );
- invite only ( cakes eaten, unhappiness value equal to );
- invite only ( cakes eaten, unhappiness value equal to );
- invite nobody ( cakes eaten, unhappiness value equal to ).
The minimum unhappiness value is achieved by inviting and .In the third test case, inviting members generates a valid party with the minimum possible unhappiness value.
相关
在以下作业中: