[2330] Luo Gu busy city

Title Description

C is a very busy city metropolis, the city road is very crowded, so the mayor decided to transform the way in which. Urban road C are distributed such that: there are n urban intersections, there are some road between intersections is connected, is connected up to a road between two intersections. The roads are two-way, and all the intersection directly or indirectly up. Each road has a value, the smaller the score the more the busy road, the need for reform. But the government's limited financial resources, the mayor want to road reconstruction, the better, so he made the following request:

1. Those road reconstruction can put all the intersections direct or indirect communication with them. 2. In the case of 1 to meet the requirements of the transformation of the road as little as possible. 3. In the case of 1,2 to meet the requirements of those road score the biggest score of the road reconstruction as small as possible.

Task: As City Planning Bureau you should make the best decisions, choose which roads should be constructed.

Input Format

The first line has two integers n, m denotes n-urban intersections, m roads.

Next is a description of m rows each road, u, v, c is connected to a road between intersections expressed u and v, score of c. (1≤n≤300,1≤c≤10000,1≤m≤100000)

Output Format

Two integers s, max, that you select a few roads, score maximum score of that road is.

Sample input and output

Input # 1
4 5
1 2 3
1 4 5
2 4 7
2 3 6
3 4 8
Output # 1
36 

Solution: Ace kruskal, prim did not how to use hhh, almost bare title ah!
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
typedef double db;
const int N=2005;
int n,m,cp,tot,fa[N],b[N];

struct node{
    int x,y;
}a[N];

struct YCLL{
    int u,v;
    int va;
}e[N];

int ans=0;

bool cmp(YCLL aa,YCLL bb){
    return aa.va<bb.va;
}

int find(int x){
    if(x!=fa[x]) 
       fa[x]=find(fa[x]);
    return fa[x];
}
int main(){
    freopen("2330.in","r",stdin);
    freopen("2330.out","w",stdout);
    scanf("%d",&n); scanf("%d",&m);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++)
        scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].va);
    sort(e+1,e+m+1,cmp);
    for(int i=1;i<=m;i++){
        int uu=find(e[i].u);
        int vv=find(e[i].v);
        if(uu==vv) continue;
        ans= E [i] .va; 
        does [u] = vv; all ++ ;
        if (all == (n- 1 )) break ; 
    } 
    Printf ( " % d% d " , n- 1 , years);
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11291446.html