BZOJ 1083: [SCOI2005]繁忙的都市

Posted ZlycerQan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BZOJ 1083: [SCOI2005]繁忙的都市相关的知识,希望对你有一定的参考价值。

二次联通门 : BZOJ 1083: [SCOI2005]繁忙的都市

 

 

 

 

/*
    BZOJ 1083: [SCOI2005]繁忙的都市

    
    最小生成树

*/
#include <cstdio>
#include <iostream>
#define rg register
#include <algorithm>
inline void read (int &n)
{
    rg char c = getchar ();
    for (n = 0; !isdigit (c); c = getchar ());
    for (; isdigit (c); n = n * 10 + c - 0, c = getchar ());
}
#define Max 1000005
struct D 
{
    int u, v, d;
    D (int a = 0, int b = 0, int c = 0) : u (a), v (b), d (c) { }
    bool operator < (const D &rhs) const
    { return d < rhs.d; }
} a[Max];
int f[Max];
inline int Find (int x) { return x == f[x] ? x : f[x] = Find (f[x]); }
inline void cmax (int &a, int b) { if (b > a) a = b; }
int main (int argc, char *argv[])
{
    int N, M; read (N), read (M); rg int i, j;
    for (i = 1; i <= M; ++ i)
        read (a[i].u), read (a[i].v), read (a[i].d);

    std :: sort (a + 1, a + 1 + M);
    for (i = 1; i <= N; ++ i) f[i] = i;
    int res = 0, x, y, C = 0;
    for (i = 1; i <= M; ++ i)
    {
        x = Find (a[i].u), y = Find (a[i].v);

        if (x != y)
        {
            ++ C, f[x] = y, cmax (res, a[i].d);
            if (C == N - 1) break;
        }
    }
    std :: cout << N - 1 << " " << res;

    return 0;
}

 

以上是关于BZOJ 1083: [SCOI2005]繁忙的都市的主要内容,如果未能解决你的问题,请参考以下文章

bzoj1083 [SCOI2005]繁忙的都市

bzoj 1083: [SCOI2005]繁忙的都市

bzoj1083: [SCOI2005]繁忙的都市(最小生成树)

BZOJ1083: [SCOI2005]繁忙的都市

BZOJ 1083: [SCOI2005]繁忙的都市Kruscal最小生成树裸题

BZOJ 1083 [SCOI2005]繁忙的都市