Nicole
Time limit1sMemory limit256 MB
Pick at least two locations with no hearing pair among them to maximize total satisfaction.
- Level
Medium5 of 10
- Topics
- Brute force, Bit manipulation, Graph
- Solved
- No attempts yet
Problem
Nicole reads a lot of physics and astronomy, so she knows what an elliptical whisper chamber is. In a large elliptical room a person standing at one focus hears a person standing at the other focus remarkably well, and the effect gets stronger under a vaulted roof shaped like part of a prolate spheroid. The National Statuary Hall in the United States Capitol and the Tabernacle at Temple Square in Salt Lake City both behave this way.
At one national contest the hall had an irregular shape with the same property between some pairs of locations. The two locations of such a pair are focal reflections of each other, so a person sitting at one of them hears the person sitting at the other one clearly. That must not happen during the contest, so two teams may not sit at a pair of locations that hear each other. Every location also has a satisfaction value, which depends on how close it is to the air conditioners, the lights and the food.
You are given the number of locations, the satisfaction value of every location, and every pair of locations that hear each other clearly. Mark some locations as closed so that at least two locations stay available and no available location hears any other available location clearly. Print the largest total satisfaction value of the available locations.
Input
The first line contains one integer , the number of test cases ().
Each test case starts with a line containing two integers and separated by a space. is the number of locations (), numbered from to , and is the number of pairs of locations that hear each other clearly ().
The next line contains positive integers separated by spaces, the satisfaction value of location , then of location , and so on up to location . Each of these values is at most 1000.
Each of the next lines contains two different integers and separated by a space (), meaning that a person at location and a person at location hear each other clearly. The same pair is never given twice.
Output
For each test case print one line Case n: R, where is the number of the test case starting from 1 and is the largest total satisfaction value of the available locations. If no choice of available locations satisfies the conditions, is -1.