My Title

cf437C The Child and Toy

/*例题http://codeforces.com/problemset/problem/437/C*/

 

贪心

利用贪心思想,一一找出最大点(这样可以保证每条边选择相对小的点权消耗掉)

#pragma G++ optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define REG register
#define REP(i,x,y) for(REG int i=x;i<=y;i++)
#define UP(i,x,y) for(REG int i=x;i>=y;i--)
#define IN inline
#define LL long long
#define inf 0x3f3f3f3f

const int maxn=2005;
LL ans=0;
int w[maxn];

int main(){
    int n,m;
    scanf("%d %d",&n,&m) ;
    REP(i,1,n) scanf("%d",&w[i]);
    REP(i,1,m){
        int x,y;
        scanf("%d %d",&x,&y);
        ans+=min(w[x],w[y]);    //stl太强了
    }
    printf("%lld",ans);       //听说longlong保智商

    return 0;
}
View Code

似乎正解是神仙图论去写

(这告诉我们要看清楚题意,仔细分析后相信自己

posted @ 2018-03-20 21:03  EvfX  阅读(294)  评论(0编辑  收藏  举报