题目链接: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相关推荐

最新文章

  1. Leangoo看板标签的用法(scrum敏捷开发)
  2. AIoT成功的关键要素
  3. 脑电分析系列[MNE-Python-5]| Python机器学习算法随机森林判断睡眠类型
  4. ajax alert表单,jQuery AJAX Post alert()不被调用
  5. JavaWeb --第一章Web基本概念
  6. jsp文字上下居中显示_微信朋友圈又有骚技巧,一键设置居中签名,好友傻眼了...
  7. CSM中一些常见问题的解决方式
  8. Nodejs动态加载路由,Nodejs遍历目录,Nodejs路由工具
  9. Chapter eight Data Structure(数据结构)
  10. 如何在Mac上管理辅助功能键盘的选项?
  11. 微信H5支付 以及退款
  12. 毫米波雷达在人体传感器中的应用
  13. GBIT51233-2016装配式木结构建筑技术标准
  14. 游戏翻译,本地化翻译如何做效果好
  15. linux如何查找交换机网址,亚美am8网址-官网首页
  16. 微信小游戏开发新手教程14-整合到一起,做出你的小游戏
  17. 【Flink实战系列】Flink 提交任务遇到 Server Response Internal server error 怎么排查
  18. Linux下文件的备份
  19. 【第66篇】行人属性识别研究综述(一)
  20. 计算机视觉相关综述整理

热门文章

  1. NH3.X与2.X使用上的一些区别
  2. WD硬盘 C1门 解决办法
  3. javascript --- JSON字符串化
  4. 学界 | CVPR 2018颁布五大奖项,何恺明获年轻学者奖
  5. EIGRP非等价负载均衡
  6. ios CGRec用法
  7. bashrcprofile
  8. phpcms_v9推送到其他栏目后再在其他栏目删除导致数据库出错
  9. 积跬步-java任职要求
  10. 通过指针便利图像元素