POJ 1287 Networking 垃圾题目
Networking
Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between two points, you are given the length of the cable that is needed to connect the points over that route. Note that there may exist many possible routes between two given points. It is assumed that the given possible routes connect (directly or indirectly) each two points in the area. Input The input file consists of a number of data sets. Each data set defines one required network. The first line of the set contains two integers: the first defines the number P of the given points, and the second the number R of given routes between the points. The following R lines define the given routes between the points, each giving three integer numbers: the first two numbers identify the points, and the third gives the length of the route. The numbers are separated with white spaces. A data set giving only one number P=0 denotes the end of the input. The data sets are separated with an empty line. Output For each data set, print one number on a separate line that gives the total length of the cable used for the entire designed network. Sample Input
Sample Output
Source |
#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
//---------------------------------Sexy operation--------------------------//
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define debug(n) printf("%d_________________________________\n",n);
#define speed ios_base::sync_with_stdio(0)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
//-------------------------------Actual option------------------------------//
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define Swap(a,b) a^=b^=a^=b
#define Max(a,b) (a>b?a:b)
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define mp(a,b) make_pair(a,b)
#define pb(n) push_back(n)
#define dis(a,b,c,d) ((double)sqrt((a-c)*(a-c)+(b-d)*(b-d)))
//--------------------------------constant----------------------------------//
#define INF 0x3f3f3f3f
#define esp 1e-9
#define PI acos(-1)
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef long long ll;
//___________________________Dividing Line__________________________________/
int n,m;
int father[1100000];
struct node
{
int x;
int y;
int k;
}Q[1100000];
int find(int x)
{
if(father[x]==x)
return x;
return father[x]=find(father[x]);
}
bool cmp(node a,node b)
{
return a.k<b.k;
}
int main()
{
while(~scanf("%d",&n)&&n)
{
cini(m);
int cont=0,sum=0,st=0;
for(int i=0;i<m;i++)
{
scanf("%d %d %d",&Q[i].x,&Q[i].y,&Q[i].k);
cont+=Q[i].k;
}
sort(Q,Q+m,cmp);
for(int i=1;i<=n;i++) father[i]=i;
for(int i=0;i<m;i++)
{
int tx=find(Q[i].x);
int ty=find(Q[i].y);
if(tx!=ty)
{
sum+=Q[i].k;
st++;
father[tx]=ty;
if(st==n-1)
break;
}
}
printf("%d\n",sum);
}
return 0;
}
POJ 1287 Networking 垃圾题目的更多相关文章
- ZOJ1372 POJ 1287 Networking 网络设计 Kruskal算法
题目链接:problemCode=1372">ZOJ1372 POJ 1287 Networking 网络设计 Networking Time Limit: 2 Seconds ...
- POJ.1287 Networking (Prim)
POJ.1287 Networking (Prim) 题意分析 可能有重边,注意选择最小的边. 编号依旧从1开始. 直接跑prim即可. 代码总览 #include <cstdio> #i ...
- POJ 1287 Networking (最小生成树)
Networking Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit S ...
- POJ 1287 Networking
题目链接: poj.org/problem?id=1287 题目大意: 你被分派到去设计一个区域的连接点,给出你每个点对之间的路线,你需要算出连接所有点路线的总长度. 题目输入: 一个数字n 代表有 ...
- POJ 1287 Networking (最小生成树)
Networking 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/B Description You are assigned ...
- POJ 1287 Networking (ZOJ 1372) MST
http://poj.org/problem?id=1287 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=372 和上次那题差 ...
- POJ 1287 Networking【kruskal模板题】
传送门:http://poj.org/problem?id=1287 题意:给出n个点 m条边 ,求最小生成树的权 思路:最小生树的模板题,直接跑一遍kruskal即可 代码: #include< ...
- poj 1287 Networking【最小生成树prime】
Networking Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7321 Accepted: 3977 Descri ...
- POJ 1287 Networking(最小生成树)
题意 给你n个点 m条边 求最小生成树的权 这是最裸的最小生成树了 #include<cstdio> #include<cstring> #include<algor ...
随机推荐
- 面试官求你了,别再问我TCP的三次握手和四次挥手
少点代码,多点头发 本文已经收录至我的GitHub,欢迎大家踊跃star 和 issues. https://github.com/midou-tech/articles 三次握手建立链接,四次挥手断 ...
- JS入门系列(1)-原型-函数原型
实例1: 首先定义一个Persion类或者说是函数 var p1 = Persion();:表示,作为普通函数调用 var p2 = new Persion();:表示,作为构造器调用 创建函数之后, ...
- 第九节:os、sys、json、pickle、shelve模块
OS模块: os.getcwd()获取当前路径os.chdir()改变目录os.curdir返回当前目录os.pardir()父目录os.makedirs('a/b/c')创建多层目录os.remov ...
- windows/linux下如何更换Python的pip源
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:xlixiaohui PS:如有需要Python学习资料的小伙伴可以 ...
- stand up meeting 11/19/2015
队员 今日工作 工作耗时/h 明日计划 计划耗时/h 冯晓云 利用昨天编写的调用必应词典API的DLL,完成了UWP版本查词APP的试水,证实了DLL可调和在线查词的可行性:和其他部分的同学就接口数据 ...
- Python - 翻译Talk Python To Me (和我聊Python) 播客
“和我聊Python”是一个美国的聊天播客,英文名Talk Python To Me,类似于喜马拉雅的音频课程节目,只不过这个主题是编程语言Python.该节目从2015年的节目到现在,已经超过256 ...
- [Abp vNext 入坑分享] - 1.创建初始的项目
一.简要说明 本篇文章主要是跟着官方的文档把项目安装好先,同时了解一下大概的项目结构. 二.具体步骤 2.1全局安装ABP CLI,直接在cmd中安装即可.如果你之前安装过,这里可以略过: dotne ...
- sk-learn实现L2岭回归,对线性回归正则化
岭回归算法: from sklearn.datasets import load_boston from sklearn.externals import joblib from sklearn.li ...
- ElasticSearch的高级复杂查询:非聚合查询和聚合查询
一.非聚合复杂查询(这儿展示了非聚合复杂查询的常用流程) 查询条件QueryBuilder的构建方法 1.1 精确查询(必须完全匹配上,相当于SQL语句中的“=”) ① 单个匹配 termQuery ...
- ES6中不得不说的关键字const
上一节讲了let关键字,它是用来声明一个变量,只在块级作用域起作用.这一节我们来学习ES6新增的另一个关键字const. const 的作用 const是constant(常量)的缩写,const和 ...