21636_Subse

2022-5-16 18:20| 发布者: Hocassian| 查看: 34| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505709884800-Problem List-采集的数据-后羿采集器.html

Pro.ID

21636

Title

Subset

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21636

AC

0

Submit

2

Ratio

0.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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, bn, 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, bn, 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
    1 2 1 2 0
    6
    1 2
    2 3
    3 1
    2 4
    4 5
    5 2
    0

    Sample Output

    3

    Source

    样例输入

    5
    1 2 1 2 0
    6
    1 2
    2 3
    3 1
    2 4
    4 5
    5 2
    0

    样例输出

    3

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部