poj3723Conscription
2024-05-16 09:19:06
题目链接:http://poj.org/problem?id=3723
建图时将女生编号都加n(男生数目),求最大生成树。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const int maxn=10000+1; 6 struct node 7 { 8 int u,v,w; 9 }; 10 node map[5*maxn]; 11 int father[2*maxn]; 12 int n,m,r; 13 bool cmp(node x,node y) 14 { 15 return x.w>y.w; 16 } 17 void Init() 18 { 19 for(int i=0;i<n+m;i++) 20 father[i]=i; 21 } 22 int find_set(int x) 23 { 24 if(father[x]==x) 25 return x; 26 else 27 return father[x]=find_set(father[x]); 28 } 29 30 int kruskal() 31 { 32 int i,sum=0; 33 Init(); 34 sort(map,map+r,cmp); 35 for(i=0;i<r;i++) 36 { 37 38 int x=find_set(map[i].u); 39 int y=find_set(map[i].v); 40 if(x!=y) 41 { 42 father[y]=x; 43 sum+=map[i].w; 44 } 45 } 46 return sum; 47 } 48 int main() 49 { 50 int t,x,y,d; 51 scanf("%d",&t); 52 while(t--) 53 { 54 scanf("%d%d%d",&n,&m,&r); 55 for(int i=0;i<r;i++) 56 { 57 scanf("%d%d%d",&x,&y,&d); 58 map[i].u=x; 59 map[i].v=y+n; 60 map[i].w=d; 61 } 62 printf("%d\n",(n+m)*10000-kruskal()); 63 } 64 return 0; 65 }
转载于:https://www.cnblogs.com/yijiull/p/6637852.html
poj3723Conscription相关推荐
最新文章
- Leangoo看板标签的用法(scrum敏捷开发)
- AIoT成功的关键要素
- 脑电分析系列[MNE-Python-5]| Python机器学习算法随机森林判断睡眠类型
- ajax alert表单,jQuery AJAX Post alert()不被调用
- JavaWeb --第一章Web基本概念
- jsp文字上下居中显示_微信朋友圈又有骚技巧,一键设置居中签名,好友傻眼了...
- CSM中一些常见问题的解决方式
- Nodejs动态加载路由,Nodejs遍历目录,Nodejs路由工具
- Chapter eight Data Structure(数据结构)
- 如何在Mac上管理辅助功能键盘的选项?
- 微信H5支付 以及退款
- 毫米波雷达在人体传感器中的应用
- GBIT51233-2016装配式木结构建筑技术标准
- 游戏翻译,本地化翻译如何做效果好
- linux如何查找交换机网址,亚美am8网址-官网首页
- 微信小游戏开发新手教程14-整合到一起,做出你的小游戏
- 【Flink实战系列】Flink 提交任务遇到 Server Response Internal server error 怎么排查
- Linux下文件的备份
- 【第66篇】行人属性识别研究综述(一)
- 计算机视觉相关综述整理