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; + ...
随机推荐
- HTML5 canvas 绘图步骤
1.先把canvas选出来,不选出来你往哪儿画! var oCan= document.getElementById('xxx'); 2.声明基于 canvas 的context对象,没他你怎么调用 ...
- servlet 项目
1.Servlet基础类,必须继承HttpServlet package com.fan; import java.io.IOException; import java.io.PrintWriter ...
- Android /data/data/app_file/目录下面安装apk无权限问题
当识别SDCard的时候 String filePath = null; String state = Environment.getExternalStorageState(); if (state ...
- 编程实现Linux下的ls -l
头文件 #ifndef __FUNC_H__ #define __FUNC_H__ #include <stdio.h> #include <stdlib.h> #includ ...
- js中的call与apply
看js权威指南里面关于call与apply方法的说明:我们可以将call()与apply()看作是某个对象的方法,通过调用方法的形式来间接调用函数.这样的解释未免使人糊涂啊.下面说一下自己的见解:其实 ...
- spring_150805_datasource
实体类: package com.spring.model; public class DogPet { private int id; private String name; private in ...
- 轻松大幅度降低 Meteor App 的首屏加载时间
许多研究表明,用户最满意的网页加载时间是在2秒以下.能够忍受的较长等待时间上限大概在6-8秒之间.如果需要等待12秒,99%以上的用户会关闭网页离开. 所以如果要给用户提供愉快的使用体验,尽量做到 2 ...
- HADOOP NAMENODE对Image和edits的处理
1.SNN CheckPoint的处理流程 配置中配置做CheckPoint的两个条件,一个是文件大小editlog大于多大就做,另一个是时间维度,多长时间做一次. (1)SNN首先检查是否需要进行c ...
- C#网页采集
/// <summary> /// 返回提取数组 /// </summary> /// <param name="rex">正则</par ...
- web.xml文件中加载顺序的优先级
在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...