bzoj1083: [SCOI2005] Busy urban bottleneck spanning tree

https://www.lydsy.com/JudgeOnline/problem.php?id=1083

The meaning of the question: give you a graph, find the minimum value of the maximum edge weight of the spanning tree

It is to find the bottleneck spanning tree (the largest edge weight in the spanning tree is the smallest). The minimum spanning tree must be the bottleneck spanning tree, but the bottleneck spanning tree is not necessarily the minimum spanning tree, and the minimum bottleneck spanning tree must be the minimum spanning tree.

/**************************************************************
    Problem: 1083
    User: walfy
    Language: C++
    Result: Accepted
    Time:40 ms
    Memory:2420 kb
****************************************************************/
 
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)
 
using namespace std;
 
const double g=10.0,eps=1e-12;
const int N=300+10,maxn=N*N+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;
 
struct edge{
    int u,v,c;
    bool operator <(const edge&rhs)const{
        return c<rhs.c;
    }
}e[maxn];
int fa [N];
int Find ( int x)
{
    return fa[x]==x?x:fa[x]=Find(fa[x]);
}
intmain ()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=0;i<m;i++)scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
    sort(e,e+m);
    int ans=0;
    for(int i=0;i<m;i++)
    {
        int x=e[i].u,y=e[i].v;
        int fx=Find(x),fy=Find(y);
        if(fx!=fy)
        {
            fa [fx] = fy;
            years = max(years,e[i].c);
        }
    }
    printf("%d %d\n",n-1,ans);
    return 0;
}
/***********************
 
***********************/
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325026862&siteId=291194637