poj 2421
来源:互联网 发布:淘宝的放心淘和运费险 编辑:程序博客网 时间:2024/05/20 02:29
最小生成树模板题,就是POJ的英文实在有点难翻译,好好的一个X,Y坐标分别对应两个村庄,数值对应村庄距离愣是说得不明不白。
代码:
#include<iostream>using namespace std;#define maxn 300000;int N,Q;int mm[105][105];int flag[105];int low[105];int sum;void prim(){ int i,j,pos,minn; flag[1]=1; low[1]=0; for(i=2;i<=N;i++)low[i]=mm[1][i]; // cout<<N<<endl; for(i=2;i<=N;i++) { pos=1; //cout<<N<<endl; minn=maxn; for(j=2;j<=N;j++) if(!flag[j]&&low[j]<minn){minn=low[j];pos=j;} sum+=minn; // cout<<minn<<" "<<pos<<endl; flag[pos]=1; for(j=2;j<=N;j++) if(!flag[j]&&low[j]>mm[pos][j])low[j]=mm[pos][j]; }}int main(){ int T,i,j; cin>>N; for(i=1;i<=N;i++) for(j=1;j<=N;j++) cin>>mm[i][j]; cin>>T; while(T--) { cin>>i>>j; mm[i][j]=mm[j][i]=0; } sum=0; prim(); cout<<sum<<endl; return 0;}
0 0
- POJ 2421
- poj 2421
- POJ 2421
- poj 2421
- POJ 2421
- POJ 2421
- poj 2421
- POJ 2421
- poj 2421
- POJ 2421Constructing Roads
- poj 2421 Constructing Roads
- poj 2421 Constructing Roads
- poj 2421(prime)
- POJ 2421 Constructing Roads
- POJ 2421 Constructing Roads
- POJ 2421 constructing roads
- POJ-2421-Constructing Roads
- POJ 2421 Constructing Roads
- 2016青岛网赛1001
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
- string stringbuffer stringbuilder
- 分布式事务的原理分析与应用
- hdu5889 Barricade(最短路+网络流)
- poj 2421
- Socket CAN 中文文档 - Linux 内核文档翻译
- java -- Exception in thread "main" java.util.ConcurrentModificationException
- 用myeclipse制作doc的时候出现以下代码:
- 下拉实现头部图片放大效果,实现类似QQ,新浪个人中心界面
- ACE Editor接入指南
- 453.Flatten Binary Tree to Linked List-将二叉树拆成链表(容易题)
- git githup 使用
- 网易编程题暗黑字符串原理解析以及Java源码