POJ 1287 Networking 最小生成树

 
在这里总结一下着几天做题的感悟,其实算法还算简单,只是你要静下心去参悟,所谓开窍了就好,所以耐心就好,还有就是现在是打基础,一定要扎牢;
Runtime Error 运行错误,一般是数组开的太小
Time Limit Exceeded 时间超限,也许是读入时没有加截至条件,程序一直在等待输入,就造成了超时,还有就是没有加!=EOF
Memory Limit Exceeded 内存超限,数组开的太大 或 太小
Presentation Exceeded 格式不对,表示输出的答案是对的,但是换行或者空格不符合输出格式要求
Output Error 表示程序输出过多的内容
Compile Error 没通过编译,编译错误
System Error 表示系统发生错误无法正常判题
Compiling 正在编译
#include<iostream>
#include<algorithm>
#include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<math.h> #include<limits.h>
#include<vector> #include<queue> #include<stack> using namespace std; #define max(a, b) a>b?a:b; #define min(a, b) a<b?a:b; #define INF 0xfffffff const int N = 3000;//给定了点的数量是50,但边的数量却没给,可以这样设任何边都想通,就是2500条边,但是为了防止runtime error struct node { int x, y, l; }maps[N]; int f[N], point, edge; bool cmp(node a, node b) { return a.l<b.l; } int Find(int x) { if(f[x]!=x) f[x]=Find(f[x]); return f[x]; } void Kruskal() { int i, ans; ans=0; for(i=0; i<edge; i++) { int ru=Find(maps[i].x); int rv=Find(maps[i].y); if(ru!=rv) { f[ru]=rv; ans+=maps[i].l; } } cout << ans << endl; } int main() { int i, j, a, b, c; while(scanf("%d", &point), point) { scanf("%d", &edge); for(j=0; j<=point; j++) f[j]=j; for(i=0; i<edge; i++) { scanf("%d%d%d", &a, &b, &c); maps[i].x=a; maps[i].y=b; maps[i].l=c; } sort(maps, maps+edge, cmp); Kruskal(); } return 0; }

转载于:https://www.cnblogs.com/wazqWAZQ1/p/4681786.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值