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

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

 //#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. 即时通讯UI-聊天界面(UITableView显示左右两人聊天)

    目录 1.创建UITableView对象并设置相关属性 2.创建cellModel模型 //枚举类型 typedef enum { ChatMessageFrom = ,//来自对方的消息 ChatM ...

  2. 评论 “App死亡潮:400万应用僵尸超八成,周期仅10月”

    点这里 原文: App死亡潮:400万应用僵尸超八成,周期仅10月 时间 2015-04-05 22:48:19  和讯科技相似文章 (16)原文  http://tech.hexun.com/201 ...

  3. POJ 1466

    #include<iostream> #include<stdio.h> #define MAXN 505 using namespace std; int edge[MAXN ...

  4. SQL技术内幕-7 varchar类型的数字和 int 类型的数字的比较+cast的适用

    DECLARE @x VARCHAR(10); DECLARE @y INT; DECLARE @z VARCHAR(10); SET @x = '1000'; SET @y = '2000'; SE ...

  5. Java加密技术

    相关链接: Java加密技术(一)——BASE64与单向加密算法MD5&SHA&MAC Java加密技术(二)——对称加密DES&AES Java加密技术(三)——PBE算法  ...

  6. PHP函数中默认参数的的写法

    函数可以定义 C++ 风格的标量参数默认值,如下所示: Example #3 在函数中使用默认参数 <?php function makecoffee($type = "cappucc ...

  7. **apache环境下 禁止显示 index of/ 目录下(如何禁止访问网站根目录)

    比如: http://123.57.49.XX6// 当这样访问的时候,可能会列出网站的根目录 如何禁止列出网站目录,方法如下: 让别人知道你的网站目录结构直接查看你目录下的所有文件是很危险的一个事情 ...

  8. 【BZOJ1878】[SDOI2009]HH的项链 离线BIT

    1878: [SDOI2009]HH的项链 Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义 ...

  9. linq 常用语句

    自己练习的 switch (productDataAnalysisQuery.DataType) { : var data = (from hp in GPEcontext.hbl_product j ...

  10. 连接池和 "Timeout expired"异常

    转自:博客园宁静.致远:http://www.cnblogs.com/zhangzhu/archive/2013/10/10/3361197.html 异常信息: MySql.Data.MySqlCl ...