设为首页 加入收藏

TOP

将边权拆成两半加到它所关联的两个点的点权中即可
2014-11-23 20:16:33 来源: 作者: 【 】 浏览:6
Tags:边权拆 两半 加到它 关联 两个点 即可

1005:


若没有边权,则对点权从大到小排序即可。。

考虑边,将边权拆成两半加到它所关联的两个点的点权中即可。

。。因为当两个人分别选择不同的点时,这一权值将互相抵消。

智商是硬伤啊

#include
#include
#include
#include
using namespace std;
double w[100001];
int main()
{
    //freopen("1005.in","r",stdin);
    int n,m,i,a,c,b;
    while(~scanf("%d%d",&n,&m))
    {
        memset(w,0,sizeof(w));
        for(i=1;i<=n;i++)scanf("%lf",&w[i]);
        for(i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            w[a]+=1.0*c/2;
            w[b]+=1.0*c/2;
        }
        double s;
        s=0;
        sort(w+1,w+n+1);
        for(i=n;i>=1;i-=2)
        {
            s+=w[i]-w[i-1];
        }
        printf("%.0lf\n",s);
    }
    return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ2342:Anniversary party(树形D.. 下一篇UVa10878 - Decode the tape

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)