|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|10 초||256 MB||2||1||1||100.000%|
Since the days of yore alchemy has been studied and practiced. The practice makes alchemists able to transmute materials into other forms. Transmuting materials requires drawing a transmutation circle on the ground. A little known fact about transmutation circles is they can be drawn inside other transmutation circles. By activating certain configurations in the correct order, more powerful transmutations can be produced. Activating circles incorrectly can have drastic effects on the alchemist’s body.
A young alchemist named Nicholas Flamel would like to learn the ways of alchemy. He has drawn several configurations of transmutation circles on the ground. When a circle is activated it burns bright red representing the element of fire. The activation itself produces no extra energy. The secret is when an outer transmutation circle is activated. When this occurs, all already active circles in the area of the activated circle quickly change to their respective complement elements. Fire changes to a cool blue representing water. Circles that were blue for water will burn fiery red once again. This change can either create or drain energy from the transmutation. Beware, energy can go negative at any time by temporarily draining the alchemist’s life force (but the spell continues to work just fine).
Nicholas wants to get as much out of his transmutations as possible. To do so requires him to activate all his circles in an order that releases the most energy. Determine the maximum amount of energy that can be released.
Input will start with a single line with an integer T giving the number of test cases, between 1 and 100 inclusive. For each set of transmutation circles there will be a line with a number N, 1 ≤ N ≤ 2000. This represents the number of transmutation circles. The next N lines contain spaced-separated integers X Y R A B. The first three integers represent the coordinates and radius of the circle, while the last two represent the energy release for going from fire to water (A), and water to fire (B). −10,000 ≤ X, Y ≤ 10,000; 1 ≤ R ≤ 10,000; −500 ≤ A, B ≤ 500.
No two circles will intersect or touch.
For each set of transmutation circles print a single integer representing the maximum energy that can be produced by activating the circles. On the following line print the permutation of the input circles that can produce that energy. If multiple permutations exist, print the one that comes first lexicographically.
1 8 0 0 100 -100 -100 0 0 50 -10 -10 0 0 10 -100 500 0 0 1 100 100 1000 1000 100 -1 1 1000 1000 50 -1 1 1000 1000 10 -1 1 1000 1000 1 -1 1
700 4 3 1 2 5 6 7 8