zoukankan      html  css  js  c++  java
  • Codeforces Round #250 (Div. 1) A. The Child and Toy 水题

    A. The Child and Toy

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/438/problem/A

    Description

    On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.

    The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.

    Help the child to find out, what is the minimum total energy he should spend to remove all n parts.

    Input

    The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ nxi ≠ yi).

    Consider all the parts are numbered from 1 to n.

    Output

    Output the minimum total energy the child should spend to remove all n parts of the toy.

    Sample Input

    4 3
    10 20 30 40
    1 4
    1 2
    2 3

    Sample Output

    40

    HINT

    题意

    给你一个图,然后让你删除所有边,每条边删除的代价是这条边两边点权的最小值

    然后问你花费多少

    题解:

    跑一遍就好了,和删边顺序无关,所以随便跑啦

    代码

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    
    int a[1005];
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        long long ans = 0;
        for(int i=1;i<=m;i++)
        {
            int x,y;scanf("%d%d",&x,&y);
            ans += min(a[x],a[y]);
        }
        printf("%lld
    ",ans);
    }
  • 相关阅读:
    www.a.shifen.com
    gstack pstack strace
    性能分析 函数粒度 函数里的一条语句 汇编 反编译 机器指令 %rbx,%rbp
    taocrypt
    sign
    Python 3.8.0 final¶ Release date: 2019-10-14
    超线程
    Python classes to extract information from the Linux kernel /proc files.
    借助中间件优化代码 将请求RequestId在服务端接收到请求在处理业务逻辑之前生成
    JVM CPU Profiler技术原理及源码深度解析
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4916982.html
Copyright © 2011-2022 走看看