Get Time

   Problem Statement  

 Problem Statement for Gperm

Problem Statement

    Hero has an undirected multigraph. (Each pair of vertices can be connected by arbitrarily many undirected edges. There may also be arbitrarily many self-loops at each vertex.) Hero's graph has exactly 50 vertices, labeled 0 through 49. The graph has at most 20 edges. You are given the list of those edges: the int[]s x and y. For each valid i, there is an edge that connects the vertices x[i] and y[i]. (Self-loops have x[i] = y[i].) Hero needs to paint all vertices red. He can paint the vertices in any order he likes, one vertex at a time. Each time he paints a vertex he has to pay a fee. The fee is computed as the number of edges that already have both endpoints red. Hero wants to minimize the sum of all fees he has to pay. Find the order in which he should paint the vertices, and return the corresponding total fee.


Parameters:int[], int[]
Method signature:int countfee(int[] x, int[] y)
(be sure your method is public)


-x will contain between 1 and 20 elements, inclusive.
-x and y will contain the same number of elements.
-Each element in x and y will be between 0 and 49, inclusive.


Returns: 1
One optimal order of painting the vertices is 49, 48, 47, ..., 3, 2, 1, 0. The first 49 times the fee is 0. After Hero paints the last vertex, the last fee is 1.
Returns: 2
One optimal order of painting these vertices is 49, 48, ..., 5, 4, 3, 0, 2, 1. The last three fees will be 0, 0, and 2.
Returns: 3
Returns: 4
Hero should first paint the 47 isolated vertices and then the remaining three vertices in any order. Regardless of the order in which Hero paints the last three vertices, the last three fees will be 0, 1, and 3.
Returns: 6
Returns: 53

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 696 Round 1 - Division I, Level One