题意:求解最小生成树,以及最小瓶颈生成树上的瓶颈边。

思路:只是求最小生成树即可。瓶颈边就是生成树上权值最大的那条边。

 //#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define INF 0x7f7f7f7f
#define pii pair<int,int>
#define LL long long
using namespace std;
const int N=; int seq[N], a[N], b[N], w[N], pre[N];
int cmp(int a,int b)
{
return w[a]<w[b];
} int find(int x)
{
return pre[x]==x? x: pre[x]=find(pre[x]);
} vector<int> edge;
int cal(int n, int m)
{
edge.clear();
int ans=;
for(int i=; i<=n; i++) pre[i]=i;
for(int i=; i<m; i++)
{
int u=find(a[seq[i]]);
int v=find(b[seq[i]]);
if( u!=v )
{
pre[u]=v; //不是同个连通块,则连接。
ans=max(ans, w[seq[i]]);
edge.push_back(seq[i]);
}
}
return ans;
} int main()
{
freopen("input.txt", "r", stdin);
int t, n, m; while(cin>>n>>m)
{
for(int i=; i<m; i++)
{
seq[i]=i;
scanf("%d%d%d", &a[i], &b[i], &w[i]);
}
sort(seq,seq+m,cmp);
cout<<cal(n, m)<<endl;
cout<<n-<<endl;
for(int i=; i<edge.size(); i++)
{
int q=edge[i];
printf("%d %d\n", a[q], b[q] );
} }
return ;
}

AC代码

POJ 1861 Network (MST)的更多相关文章

  1. POJ 1144 Network(割点)

    Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...

  2. POJ 1144 Network(Tarjan)

    题目链接 题意 : 找出割点个数. 思路 : Tarjan缩点,u是割点的充要条件是:u要么是具有两个以上子女的深度优先生成树的根,要么不是根,而有一个子女v满足low[v]>=dfn[u]. ...

  3. POJ 1847 Tram (最短路径)

    POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...

  4. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  5. COJ 0500 杨老师的路径规划(MST)最小生成树

    杨老师的路径规划(MST) 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 为满足同学们需求,杨老师在实验楼4层新建了好多个计算 ...

  6. ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法

    题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...

  7. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

  8. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  9. ZOJ - 1586 QS Network (Prim)

    ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...

随机推荐

  1. 用ScriptEngine在java中和javascript交互的例子(JDK6新特性)

    package demo7; import java.util.Arrays; import java.util.List; import javax.script.Invocable; import ...

  2. HDU5008 Boring String Problem(后缀数组)

    练习一下字符串,做一下这道题. 首先是关于一个字符串有多少不同子串的问题,串由小到大排起序来应该是按照sa[i]的顺序排出来的产生的. 好像abbacd,排序出来的后缀是这样的 1---abbacd ...

  3. POJ 3320

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6496   Accept ...

  4. 转:jxl导出excel(合并单元格)

    Demo 代码如下: import java.io.*; import jxl.*; import jxl.format.UnderlineStyle; import jxl.write.*; pub ...

  5. java基础知识回顾之抽象类和接口的区别

    /* 抽象类和接口的异同点: 相同点: 都是不断向上抽取而来的. 不同点: 1,抽象类需要被继承,而且只能单继承. 接口需要被实现,而且可以多实现. 2,抽象类中可以定义抽象方法和非抽象方法,子类继承 ...

  6. java 关于mysql

    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after co ...

  7. ***Xcode Interface Builder或Storyboard中可建立那两种连接?

    在Xcode Interface Builder或Storyboard中,可建立到输出口(IBOutlet)和操作(方法,IBAction)的连接. IBOutlet are for output C ...

  8. Android 注入详解

    Android下的注入的效果是类似于Windows下的dll注入,关于Windows下面的注入可以参考这篇文章Windows注入术.而Android一般处理器是arm架构,内核是基于linux,因此进 ...

  9. 23种设计模式学习一(单列模式)singleton

    单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...

  10. 【转】terminal 快捷键

    转自:http://www.jb51.net/os/Ubuntu/141723.html 1.gnome-terminal快捷键设置方法: 系统 —> 首选项 ->键盘快捷键 -> ...