TOJ 4117 Happy tree friends
来源:互联网 发布:php 非阻塞io 编辑:程序博客网 时间:2024/05/29 15:33
It's a problem of minimum spanning tree,I think it a directed graph that have differences with undirected graph .But it's complete graph.It none of directed business.Use kruskal algorithm to solve this problem.
The portal:http://acm.tju.edu.cn/toj/showp4117.html
#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace std;struct Edge{ int x,y,cap;};int bin[105];Edge edge[10005];int fee[105][105];int ans;int findx(int x){ if(x != bin[x]) bin[x] = findx(bin[x]); return bin[x];}int merge_(int x,int y){ int fx = findx(x); int fy = findx(y); if(fx == fy) return 1; bin[fy] = fx; return 0;}int cmp(const void * a1,const void * a2){ struct Edge p1 = *(struct Edge *)a1; struct Edge p2 = *(struct Edge *)a2; return p1.cap - p2.cap;}void Deal_with(){ int n; while(~scanf("%d",&n)){ int tempa,cnt = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d",&tempa); fee[i][j] = tempa; if(i == j)continue; edge[cnt].x = i; edge[cnt].y = j; edge[cnt].cap = tempa; cnt ++; } } int u,v; scanf("%d %d",&u,&v); for(int i=1;i<=100;i++){ bin[i] = i; } qsort(edge,cnt,12,cmp); merge_(u,v); ans = fee[u][v]; for(int i=0;i<cnt;i++){ //printf("%d %d %d\n",edge[i].x,edge[i].y,edge[i].cap); if(merge_(edge[i].x,edge[i].y)){ continue; } else{ ans += edge[i].cap; } } printf("%d\n",ans); }}int main(void){ //freopen("a.in","r",stdin); Deal_with(); return 0;}
0 0
- TOJ 4117 Happy tree friends
- 最小生成树 TOJ 4117 Happy tree friends
- TJU-4117 Happy tree friends(最小生成树)
- TOJ 2469. Friends
- TOJ 2469 — Friends
- My Friends, Happy Xmas
- Happy Matt Friends (DP)
- HDU5119.Happy Matt Friends
- HDOJ4931 - Happy Three Friends
- [4931]:Happy Three Friends
- Happy Matt Friends HDU
- TOJ 4284 Happy watering / 贪心
- TOJ 3471.Happy XiaoXiao Guo
- hdu 4931 Happy Three Friends
- HDU 4931 Happy Three Friends
- hdu 5119 Happy Matt Friends
- HDOJ 4931 Happy Three Friends
- hdu5119 Happy Matt Friends( DP )
- poj 1532 【求无向图的所有割点 以及 该点分成的BCC数目】
- Android控件的一些属性
- linux0.12之内核代码signal.c说明
- Win7局域网打印机共享设置(详细图文流程)
- JSP四个作用域
- TOJ 4117 Happy tree friends
- 图说 web应用的基本结构和web.xml
- js内存分析
- $_SERVER参数详解
- 查看jquery绑定的事件函数
- 奥莉霸气睡姿曝光 脚压妈妈李安琪李小鹏诉苦
- unity3d在android下的真机测试<转载>
- Java 通过 JNA 调用 DLL 返回 char * 字符串乱码问题的解决
- win7通过esayBCD安装ubuntu14.04