$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$J$题

贪心。

优先删除$power$大的点。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-; const int maxn=;
int p[maxn],n;
vector<int>g[maxn];
struct X { int h,p; }s[maxn];
bool f[maxn]; bool cmp(X a,X b) {return a.p>b.p;}
int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%d",&s[i].p), s[i].h=i;
p[i]=s[i].p;
}
sort(s+,s++n,cmp); memset(f,,sizeof f);
for(int i=;i<=n;i++) g[i].clear();
for(int i=;i<=n-;i++)
{
int a,b; scanf("%d%d",&a,&b);
g[a].push_back(b); g[b].push_back(a);
} LL ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<g[s[i].h].size();j++)
{
int to=g[s[i].h][j];
if(f[to]) continue;
ans=ans+(LL)p[to];
}
f[s[i].h]=;
}
cout<<ans<<endl;
}
return ;
}

XTU 1252 Defense Tower的更多相关文章

  1. XTUOJ 1252 Defense Tower 贪心

    题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1252 思路:考虑每条边对玩家的伤害 假设连接的节点是u,v,破坏 ...

  2. [ZOJ 3623] Battle Ships

    Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is s ...

  3. ZOJ3623:Battle Ships(全然背包)

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  4. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  5. Battle Ships(复习泛化物品**)

    传送门Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which i ...

  6. zoj3623 Battle Ships

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  7. dp --- hdu 4939 : Stupid Tower Defense

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  8. hdu4939 Stupid Tower Defense (DP)

    2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131 ...

  9. Stupid Tower Defense

    Problem Description FSF is addicted to a stupid tower defense game. The goal of tower defense games ...

随机推荐

  1. memcached内存分配及回收初探

    对memcached(后面简称mc) 的内存分配及回收机制进行了深度分析和测试,以下是一些学习的心得,和大家共同探讨一下,期望能抛砖引玉 mc简介: mc是由LiveJournal技术团队开发的一套分 ...

  2. 【Bootstrap】Bootstrap Datepicker使用

    插件:http://url.cn/V4S8w4 1.添加样式和引用JS文件 <link href="CSS/bootstrap-datetimepicker.css" rel ...

  3. C#自动选择出系统中最合适的IP地址

    写这个是因为很长时间以来,碰到过很多次这个问题,但都没当回事,这次又碰到了这个老问题,无奈百度了一圈儿未果,身边又没有大牛可以请教,就自己先“总结”了一套方法,一来给自己记录,二来如果碰巧能有朋友看到 ...

  4. Nginx 配置基于域名的虚拟

    编辑配置文件 vi /etc/nginx/nginx.conf user    www www; worker_processes  2; error_log  logs/error.log  not ...

  5. SQL2008R2 无法读取此系统上以前注册的服务器的列表--网上方法不可行

    C:\Users\<username>\AppData\Local\Temp,然后创建两个命名为1和2的文件夹

  6. 搭建一个完整的Java开发环境

    搭建一个完整的Java开发环境 作为一个Java程序员,配置一个java开发环境是必备的技能,今天给广大菜鸟初学者补上一课.环境的配置,大概就分三个1,JDK 2,Tomcat(或者其他的)3,ecl ...

  7. JS简单验证密码强度

    <input type="password" id="password" value=""/><button id=&qu ...

  8. LESS编译方案

    我的LESS编译方案 2013-08-07 10:22 by 逆风之羽, 469 阅读, 2 评论, 收藏, 编辑 背景 近期项目前端决定使用less,简单介绍一下,详细信息有兴趣查看官方文档(htt ...

  9. Java集合概述、Set集合(HashSet类、LinkedHashSet类、TreeSet类、EnumSet类)

    Java集合概述.Set集合(HashSet类.LinkedHashSet类.TreeSet类.EnumSet类) 1.Java集合概述1)数组可以保存多个对象,但数组长度不可变,一旦在初始化数组时指 ...

  10. VS2012下使用Moq进行单元测试

    单元测试虽然是个很老的东西了,但平时写代码一般都不写测试,因为VS调试完全可以满足了,所以一直也就没有用过,刚好在<Pro.ASP.NET.MVC.3.Framework>中看到了Moq这 ...