BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(最大生成树)
这很明显就是最大生成树= =
CODE:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1010
#define maxm 20010
struct edges{
int x,y,z;
}edge[maxm];
bool cmp(edges a,edges b){return (a.z>b.z);}
int f[maxn];
int fin(int x){if (f[x]!=x) f[x]=fin(f[x]);return f[x];}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) f[i]=i;
for (int i=1;i<=m;i++) scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].z);
sort(edge+1,edge+1+m,cmp);
int sum=0,ans=0;
for (int i=1;i<=m;i++){
int x=fin(edge[i].x),y=fin(edge[i].y);
if (x!=y) { f[x]=y;sum++;ans+=edge[i].z;if (sum==n-1) {printf("%d",ans);return 0;}}
}
printf("-1\n");
return 0;
}
BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(最大生成树)的更多相关文章
- bzoj 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 -- 最大生成树
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MB Description 奶牛贝 ...
- BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
题目 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 53 Solve ...
- bzoj 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复【最大生成树】
裸的最大生成树,注意判不连通情况 #include<iostream> #include<cstdio> #include<algorithm> using nam ...
- 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 69 Solved: ...
- 【BZOJ】3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=3390 .. #include <cstdio> #include <cstring ...
- BZOJ3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 43 Solved: ...
- BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班
题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- Bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 最短路,神题
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 218 Solved: ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏( dfs )
因为是棵树 , 所以直接 dfs 就好了... ---------------------------------------------------------------------------- ...
随机推荐
- angularjs ajax传参
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- Struts2验证
一.声明式验证 1.字段验证 fielderror的两种显示方式 fielderror的提示信息可以国际化 2.非字段验证:actionErrors / <s:actionerror> 例 ...
- EclipseEE导入项目出现的那些问题
1.显示.project文件丢失, 解决方法:在eclipse中删除和该项目相同的文件名,重新import即可 2.导入没有.classpath和.project文件的项目 解决方法:目前没遇到 3. ...
- robotium从入门到放弃 二 第一个实例
1.导入被测试的源码 我们先下载加你计算器源码,下载地址: https://robotium.googlecode.com/files/AndroidCalculator.zip 如果地址被墙无法现在 ...
- sqlite3编译
1.sqlite3编译: 1.PC版: 1.解压: tar xvf sqlite-autoconf-3140100.tar.gz cd sqlite-autoconf-3140100/ 2.检查配置 ...
- Selenium2(java)定位页面元素 二
辅助工具: chrome浏览器,F12打开控制台; Firefox浏览器,F12打开控制台; 或者选中要定位的元素右键 安装firefox扩展firebug和firepath; 安装之后F12可调用f ...
- #搜索# #BFS# #优先队列# ----- OpenJudge鸣人和佐助
OpenJudge 6044:鸣人和佐助 总时间限制: 1000ms 内存限制: 65536kB 描述 佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐 ...
- Spring4 Hibernate4 Struts2在WebLogic 10.3.3上面部署
折腾了4天,终于可以部署了: 1,lib下面的包: antlr-2.7.7.jarasm-5.0.2.jarasm-commons-5.0.2.jarasm-tree-5.0.2.jarc3p0-0. ...
- sqlserver查询数据库中有多少个表
sql server 数表: select count(1) from sysobjects where xtype='U' 数视图: select count(1) from sysobjects ...
- 获取FMS的状态信息
application.getStats() application.getStats() Returns statistics about an application. Returns An Ob ...