POJ 1861 Network (MST)
题意:求解最小生成树,以及最小瓶颈生成树上的瓶颈边。
思路:只是求最小生成树即可。瓶颈边就是生成树上权值最大的那条边。
//#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)的更多相关文章
- POJ 1144 Network(割点)
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- POJ 1144 Network(Tarjan)
题目链接 题意 : 找出割点个数. 思路 : Tarjan缩点,u是割点的充要条件是:u要么是具有两个以上子女的深度优先生成树的根,要么不是根,而有一个子女v满足low[v]>=dfn[u]. ...
- POJ 1847 Tram (最短路径)
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- COJ 0500 杨老师的路径规划(MST)最小生成树
杨老师的路径规划(MST) 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 为满足同学们需求,杨老师在实验楼4层新建了好多个计算 ...
- ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
- ZOJ - 1586 QS Network (Prim)
ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...
随机推荐
- POJ 1491
#include<iostream> #include<cmath> #include<iomanip> #define MAXN 50 using namespa ...
- redis rdb
http://blog.chinaunix.net/uid-1757778-id-3977331.html
- Xamarin for Visual Studio 3.11.666 Beta版 破解补丁
注意:本版本是 Beta 版 现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...
- poj 1678 I Love this Game!
思路:这题和博弈论的关系不大,主要是DP.记忆化搜索即可!!! 取的数一定是大于0的,所以将负数去掉!! 代码如下: #include<iostream> #include<cstd ...
- iOS多线程 GCD
iOS多线程 GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. dispatch queue分成以下三种: 1)运行在主线程的Main que ...
- 华为OJ:火车进站
火车进站 给定一个正整数N代表火车数量,0<N<10,接下来输入火车入站的序列,一共N辆火车,每辆火车以数字1-9编号.要求以字典序排序输出火车出站的序列号. 输入描述: 有多组测试用例, ...
- Android核心分析之十九电话系统之GSMCallTacker
GSMCallTracker在本质上是一个Handler.<IGNORE_JS_OP> 1.jpg (1.52 KB, 下载次数: 1) 下载附件 保存到相册 2012-3-22 11: ...
- JAVA数据库连接池实现(转)
连接池的管理用了了享元模式,这里对连接池进行简单设计. 一.设计思路 1.连接池配置属性DBbean:里面存放可以配置的一些属性 2.连接池接口IConnectionPool:里面定义一些基本的获取连 ...
- Gravitational Teleport 是一个先进的 SSH 服务器,基于 Golang SSH 构建,完全兼容 OpenSSH
Gravitational Teleport 是一个先进的 SSH 服务器,可通过 SSH 或者 HTTPS 远程访问 Linux 服务器.其目的是为了替代 sshd.Teleport 可以轻松让团队 ...
- 查看Linux系统网卡信息
nmcli是一款能够方便我们配置网络的工具,能够轻松的查看网卡信息或网络状态: 实例1:查看网卡信息 [root@localhost ~]# nmcli connection show 名称 UUID ...