zoukankan      html  css  js  c++  java
  • noi.ac #39

    一句话题意:对于给出的一个图的任意一些点,这些点之间互联的边数小于这些点的总点数,删边使得满足要求,求删边的最小代价。

    这种脑残玩意也一眼看不出来吗?我透。。

    完了完了入土了。。

    (TM) 就是一个裸的最大生成树啊我透。。

    看来自己真是有够垃圾的呢。。。

    好了给代码。。。

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int N = 5e5 + 10;
    template<class I>
    inline void rd(I &x) {
    	ll f = 1;
    	char c = getchar();
    	for(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
    	for(x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = getchar());
    	x *= f;
    }
    int n, m;
    int fa[N];
    int get(int x) {
    	return x == fa[x] ? x : fa[x] = get(fa[x]);
    }
    struct edge {
    	int x, y, z;
    	inline bool operator < (const edge &a) const {
    		return z > a.z;
    	}
    } e[N];
    ll ans;
    int main() {
    	rd(n), rd(m);
    	for(int i = 1; i <= n; i++) fa[i] = i;
    	for(int i = 1; i <= m; i++)
    		rd(e[i].x), rd(e[i].y), rd(e[i].z), ans += e[i].z;
    	sort(e + 1, e + m + 1);
    	for(int i = 1; i <= m; i++) {
    		int x = get(e[i].x);
    		int y = get(e[i].y);
    		if(x == y) continue;
    		fa[x] = y;
    		ans -= e[i].z;
    	}
    	cout << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    julia文件合并排序.jl
    julia生成指定格式的字符串.jl
    Julia中文教程资源.txt
    python socket发送魔法包网络唤醒开机.py
    julia与python中的列表解析.jl
    python利用or在列表解析中调用多个函数.py
    Django Admin流程
    meeting
    会议
    数据库
  • 原文地址:https://www.cnblogs.com/11haonb/p/11624202.html
Copyright © 2011-2022 走看看