Pro.ID21636 TitleSubset Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21636 AC0 Submit2 Ratio0.00% 时间&空间限制描述A simple graph is an undirected graph. It has no self loop edges and no parallel edges, which means that no two distinct edges have exactly the same pair of ends. Given a simple graph, in which each vertex has a weighted value, and each edge can only belong to at most one simple cycle. Your task is to find a set of vertices, no two vertices in this set are adjacent, and the sum of weights of the vertices in the set should be maximized. 输入Input contains several cases. The first line of each case contains an integer n ( 1 ≤ n ≤ 10 000 ), which is the number of nodes. The second line contains n integers (each equal to or larger than 0, less than 10000 ). The i-th number is the weight of the i-th node. The third line contains an integer m, which is the number of edges. Each of the following m lines contains two integers a and b, 1 ≤ a, b ≤ n, representing that there is an edge between a and b. The input ended by n=0. 输出Description A simple graph is an undirected graph. It has no self loop edges and no parallel edges, which means that no two distinct edges have exactly the same pair of ends. Given a simple graph, in which each vertex has a weighted value, and each edge can only belong to at most one simple cycle. Your task is to find a set of vertices, no two vertices in this set are adjacent, and the sum of weights of the vertices in the set should be maximized. Input Input contains several cases. The first line of each case contains an integer n ( 1 ≤ n ≤ 10 000 ), which is the number of nodes. The second line contains n integers (each equal to or larger than 0, less than 10000 ). The i-th number is the weight of the i-th node. The third line contains an integer m, which is the number of edges. Each of the following m lines contains two integers a and b, 1 ≤ a, b ≤ n, representing that there is an edge between a and b. The input ended by n=0. Output Output one integer for each input case, representing the total weight of the largest independent subset. Sample Input 5 Sample Output 3 Source 样例输入5 样例输出3 作者 |