几何 + 思路构造 + 高斯消元 Destroy Walls HDU - 6187

4人阅读 评论(0) 收藏 举报
分类:
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long

const int MAXV=100000+3;
const int MAXE=200000+3;

struct Edge
{
    int from, to, cost;
    Edge(int f=0, int t=0, int c=0):from(f), to(t), cost(c){}
    bool operator < (const Edge &other)const
    {
        return cost>other.cost;
    }
}edge[MAXE];

int V, E;
int par[MAXV], high[MAXV];

int findfather(int x)
{
    return par[x]=par[x]==x?x:findfather(par[x]);
}

bool unite(int a, int b)
{
    int fa=findfather(a), fb=findfather(b);
    if(fa==fb)
        return false;
    if(high[fa]>high[fb])
        par[fa]=fb;
    else
    {
        par[fb]=fa;
        if(high[fa]==high[fb])
            ++high[fb];
    }
    return true;
}

void init()//初始化
{
    for(int i=0;i<=V;++i)
    {
        par[i]=i;
        high[i]=0;
    }
}

int main()
{
    while(~scanf("%d%d", &V, &E))
    {
        init();
        for(int i=0;i<V;++i)
        {
            int x, y;
            scanf("%d%d", &x, &y);
        }
        LL ans=0;
        for(int i=0;i<E;++i)
        {
            scanf("%d%d%d", &edge[i].from, &edge[i].to, &edge[i].cost);
            ans+=edge[i].cost;
        }
        sort(edge, edge+E);
        int cnt=0;//保留的边数
        for(int i=0;i<E;++i)
            if(unite(edge[i].from, edge[i].to))
            {
                ans-=edge[i].cost;
                ++cnt;
            }
        printf("%d %lld\n", E-cnt, ans);
    }

    return 0;
}

查看评论

HDU 6187 Destroy Walls(对偶图最小生成树)

Destroy WallsTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
  • Yasola
  • Yasola
  • 2017-09-06 08:58:06
  • 432

HDU-6187:Destroy Walls

Destroy Walls                                                               Time Limit: 8000/4000 M...
  • Mitsuha_
  • Mitsuha_
  • 2017-09-02 19:37:20
  • 512

hdu 6187 Destroy Walls

Long times ago, there are beautiful historic walls in the city. These walls divide the city into man...
  • mengzhongsharen
  • mengzhongsharen
  • 2017-11-03 18:24:48
  • 72

HDU 6187 Destroy Walls(最大生成树)

Long times ago, there are beautiful historic walls in the city. These walls divide the city into man...
  • qq_37497322
  • qq_37497322
  • 2017-09-05 19:46:42
  • 147

HDU 6187 Destroy Walls(最大生成树-Kruskal)

Description 国王的领地被一些城市和城市之间的城墙分成若干区域,国王的城堡在(0.6∗2–√,0.6∗3–√)(0.6∗2,0.6∗3)(0.6*\sqrt{2},0.6*\sqrt{3}...
  • V5ZSQ
  • V5ZSQ
  • 2018-02-14 11:09:25
  • 49

【HDU 6187 】Destroy Walls 【平面图+最大生成树】

Destroy WallsTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
  • qq_37383726
  • qq_37383726
  • 2017-09-14 19:55:38
  • 143

hdu 6187(并查集

Destroy Walls                                                               Time Limit: 8000/4000 M...
  • qq_36553623
  • qq_36553623
  • 2017-09-04 21:52:49
  • 220

hdu 3364 Lanterns 高斯消元,模板题

#include #include #include #include #include #include #include #include using namespace std;...
  • a601025382s
  • a601025382s
  • 2013-09-17 18:58:35
  • 2104

Destroy Walls

HDU 6187 给定n平面点一级m条边连接这些点,问最少去掉多少条边,以及在这情况下去掉边的点权最少,使得整个图是一个连通图。 其实仔细想一下就能发现满足这个条件当且仅当这些围墙不存在环,就是...
  • lzh823046544
  • lzh823046544
  • 2017-09-01 11:55:52
  • 126
    个人资料
    持之以恒
    等级:
    访问量: 1453
    积分: 763
    排名: 6万+
    文章存档