poj 2421 Constructing Roads MST
来源:互联网 发布:奈良吉野樱花酒淘宝 编辑:程序博客网 时间:2024/05/04 21:51
一开始看错题了,是有已建好的路,看成必须要建的路了,prim很水
/*author:jxylang:C/C++university:China,Xidian University**If you need to reprint,please indicate the source***/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#define INF 1E9using namespace std;int d[101][101];int vis[101];int dis[101];int K;int main(){ int n,m; while(~scanf("%d",&n)&&n) { memset(vis,0,sizeof(vis)); memset(dis,127,sizeof(dis)); int i,j,a,b; K=1; for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&d[i][j]); scanf("%d",&m); int ans=0,Min,t; for(i=0;i<m;i++) { scanf("%d%d",&a,&b); a--,b--; d[a][b]=d[b][a]=0; } int now=0; for(i=0;i<n;i++) { Min=INF; for(j=0;j<n;j++) { if(dis[j]>=Min||vis[j])continue; Min=dis[j];now=j; } vis[now]=1; if(now)ans+=Min; for(j=0;j<n;j++) { if(vis[j])continue; dis[j]=min(dis[j],d[now][j]); } } printf("%d\n",ans); }}
- poj 2421 Constructing Roads MST
- [MST]POJ 2421&HDU 1102 Constructing Roads
- POJ 2421 Constructing Roads (MST)
- poj 2421 Constructing Roads mst(…
- HDU 1102/POJ 2421 Constructing Roads(MST&Prim优化)
- HDU 1102 && POJ 2421 Constructing Roads (经典MST~Prim)
- POJ 2421Constructing Roads
- poj 2421 Constructing Roads
- poj 2421 Constructing Roads
- POJ 2421 Constructing Roads
- POJ 2421 Constructing Roads
- POJ 2421 constructing roads
- POJ-2421-Constructing Roads
- POJ 2421 Constructing Roads
- POJ:2421 Constructing Roads
- poj 2421Constructing Roads
- POJ 2421 Constructing Roads
- POJ 2421 Constructing Roads
- How to Estimate a Web Site Project
- 《大话Linux》第四话:那些年我们追过的Linux发行版
- [Android] Android开发优化之——从代码角度进行优化
- java动态代理(JDK和cglib)
- C++宏定义中的 #,#@,##
- poj 2421 Constructing Roads MST
- Lync 二次开发-对单个联络人和联系人组发送即时消息
- eclipse 用CTRL+Z退多了 怎么回去?
- 大数据处理利器——幂律模型
- Redhat Linux 硬盘挂载方法
- ubuntu10.10 apt-get 总失败 解决办法
- nandwrite 参数
- jquery 计时器示例
- 解决NDK *** note: the mangling of 'va_list' has changed in GCC 4.4