码迷,mamicode.com
首页 > 其他好文 > 详细

noi.ac #39

时间:2019-10-05 12:29:34      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:define   bool   之间   要求   long   sort   for   namespace   efi   

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

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

完了完了入土了。。

\(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;
}

noi.ac #39

标签:define   bool   之间   要求   long   sort   for   namespace   efi   

原文地址:https://www.cnblogs.com/11haonb/p/11624202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!