Dark roads--hdoj
Dark roads
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 1
Dollar per meter and day. To save money, they decided to no longer illuminate every road, but to switch off the road lighting of some streets. To make sure that the inhabitants of Byteland still feel safe, they want to optimize the lighting in such a way,
that after darkening some streets at night, there will still be at least one illuminated path from every junction in Byteland to every other junction.
What is the maximum daily amount of money the government of Byteland can save, without making their inhabitants feel unsafe?
and m-1 ≤ n ≤ 200000. Then follow n integer triples x, y, z specifying that there will be a bidirectional road between x and y with length z meters (0 ≤ x, y < m and x ≠ y). The graph specified by each test case is connected. The total length of all roads
in each test case is less than 2[sup]31[/sup].
7 11
0 1 7
0 3 5
1 2 8
1 3 9
1 4 7
2 4 5
3 4 15
3 5 6
4 5 8
4 6 9
5 6 11
0 0
51
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int pre[200010],n,m;
struct s
{
int x,y,v;
}b[200010];
int cmp(s n1,s n2)
{
return n1.v<n2.v;
}
int find(int a)
{
int r=a,i,j;
while(r!=pre[r])
r=pre[r];
i=a;
while(i!=r)
{
j=pre[i];
pre[i]=r;
i=j;
}
return r;
}
int fun()
{
int sum=0,i,j,k;
for(i=0;i<m;i++)
{
int fa,fb;
fa=find(b[i].x);
fb=find(b[i].y);
if(fa!=fb)
{
pre[fa]=fb;
sum+=b[i].v;
}
}
return sum;
}
int main()
{
//int n,m;
while(scanf("%d%d",&n,&m)!=EOF,n||m)
{
int i,sum=0,ans;
for(i=0;i<=n;i++)
pre[i]=i;
for(i=0;i<m;i++)
{
scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].v);
sum+=b[i].v;
}
sort(b,b+m,cmp);
ans=fun();
printf("%d\n",sum-ans);
}
}
Dark roads--hdoj的更多相关文章
- hdu 2988 Dark roads
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2988 Dark roads Description Economic times these days ...
- Dark roads(kruskal)
Dark roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- HDU 2988 Dark roads(kruskal模板题)
Dark roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【HDOJ】2988 Dark roads
最小生成树. /* */ #include <iostream> #include <string> #include <map> #include <que ...
- Jungle Roads --hdoj
Jungle Roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- Constructing Roads --hdoj
Constructing Roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- UVa 11631 - Dark roads
题目大意:政府为了减小开支决定关闭一些路灯,同时保证照亮的路能连接所有路口. 又是一个MST问题,Kruskal算法,不过数据规模比较大,又Submission Error了...扔这吧... #in ...
- HDU 2988 Dark roads (裸的最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2988 解题报告:一个裸的最小生成树,没看题,只知道结果是用所有道路的总长度减去最小生成树的长度和. # ...
- HDU2988-Dark roads,HDU1233-还是畅通工程-最小生成树
最小生成树: 中文名 最小生成树 外文名 Minimum Spanning Tree,MST 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的 ...
- HDU 2988.Dark roads-最小生成树(Kruskal)
最小生成树: 中文名 最小生成树 外文名 Minimum Spanning Tree,MST 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的 ...
随机推荐
- VMWare linux安装mysql 5.7.13
1.基础环境说明 虚拟机:VMWare 操作系统:linux 数据库版本:mysql 5.7.13 社区版(别问为什么不装企业版,因为企业版要钱) 背景:虚拟机可以连上外网 下载目录: /tools/ ...
- js date 转化为字符串函数
getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31). getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6). getFullYear() 从 Date 对象 ...
- ASP.net获取当前url各种属性(文件名、参数、域名等)的方法
假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.te ...
- 在MFC中使用Cstring
此文介绍了关于MFC使用CString的资料,可一参考一下. 转自于VC知识库:http://www.vckbase.com/index.php/wv/829 通过阅读本文你可以学习如何有效地使用 C ...
- C#遍历/反射 属性/字段
public static string SortParam<T>(T t) { string tStr = string.Empty; if (t == null) { return s ...
- Redis-RDB持久化设置
1.如何配置RDB持久化机制redis.conf文件,也就是/etc/redis/6379.conf,去配置持久化 save 60 1000 每隔60s,如果有超过1000个key发生了变更,那么就生 ...
- 非传统题初探——AtCoder Practice Contest #B - インタラクティブ練習 (Interactive Sorting)
原题: Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement This is an interac ...
- Linux思维导图之sed、实战习题
命令解释: ◆sed 2p /etc/passwd第二行打印了两次其余一次 ◆sed-n '2p' /etc/passwd 只打印出第二行 ◆sed-n 1,4p' /etc/passwd 只打印出1 ...
- 7.IDEA创建Web项目和Tomcat配置
IntelliJ IDEA Tomcat配置 详解 Tomcat 7.0 和jdk1.8 一起使用 一.创建web项目 1.1 创建工程 1.2 创建java web项目并创建web.xml文件 1 ...
- android 权限问题分析
Android系统是运行在Linux内核上的,Android与Linux分别有自己的一套严格的安全及权限机制, 很多像我这样的新手,尤其是习惯了windows低安全限制的用户,很容易在这方面弄混淆,下 ...