当前位置: 首页 > news >正文

内地与香港直通车或永久停运吗seo关键词排名优化推荐

内地与香港直通车或永久停运吗,seo关键词排名优化推荐,做留言的网站,小程序定制开发流程一.介绍 Prim算法是一种用于解决最小生成树问题的贪心算法。最小生成树问题是指在一个连通无向图中找到一个生成树,使得树中所有边的权重之和最小。 Prim算法的基本思想是从一个起始顶点开始,逐步扩展生成树,直到覆盖所有顶点。具体步骤如下…

一.介绍

 Prim算法是一种用于解决最小生成树问题的贪心算法。最小生成树问题是指在一个连通无向图中找到一个生成树,使得树中所有边的权重之和最小。

Prim算法的基本思想是从一个起始顶点开始,逐步扩展生成树,直到覆盖所有顶点。具体步骤如下:

  1. 选择一个起始顶点作为生成树的根节点,并将其加入生成树中。
  2. 从生成树中的顶点出发,选择一条与生成树相连的边中权重最小的边,并将其加入生成树中。
  3. 重复步骤2,直到生成树包含了所有顶点。

Prim算法的关键在于如何选择与生成树相连的边中权重最小的边。一种常用的方法是使用优先队列(最小堆)来存储候选边,每次选择权重最小的边加入生成树。

Prim算法的时间复杂度为O(ElogV),其中V是顶点数,E是边数。它是一种有效的算法,适用于稠密图和稀疏图。


 二.Prim与Dijkstra

其实Prim算法和Dijkstra算法差不多,就是一点小的改进,分别在第29,32,33行。

29:统计sum数量,若sum<n,说明无法构成最小树,因为构成最小树的点都不够!

32,33:w<dis[v]即可,因为只需要点到点,不是点到起点.


三.题目:

P3366 【模板】最小生成树 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)


四.【AC】代码 

#include<bits/stdc++.h>
#define maxn 200005
#define inf 0x7fffffff
using namespace std;
int n,m,ans=0,sum=0;
int head[5001],dis[5001];
bool vis[maxn],flag=0;
//链式前向星
struct Edge{int u,v,w,next;
}edge[maxn<<1]; //无向图,要*2
int cnt=0;
void add(int u,int v,int w){edge[++cnt]=(Edge){u,v,w,head[u]};head[u]=cnt;
} 
struct node{int u,w;bool operator < (const node &x) const{return x.w<w;}
};
void Prim(){for(int i=2;i<=n;i++) dis[i]=inf;dis[1]=0;priority_queue<node> q;q.push((node){1,0});while(!q.empty()){node temp=q.top();q.pop();int u=temp.u;if(vis[u]) continue;vis[u]=1;sum++;ans+=temp.w;for(int i=head[u];i;i=edge[i].next){int v=edge[i].v,w=edge[i].w;if(w<dis[v]){dis[v]=w;q.push((node){v,dis[v]});}}}
}
int main(){//输入数据 cin>>n>>m;for(int i=1;i<=m;i++){int u,v,w;cin>>u>>v>>w;add(u,v,w);add(v,u,w);}//调用算法 Prim();//输出答案if(sum==n) cout<<ans;else cout<<"orz"; return 0;
}


文章转载自:
http://fructan.c7630.cn
http://thaumatology.c7630.cn
http://relieved.c7630.cn
http://cognisant.c7630.cn
http://fado.c7630.cn
http://neufchatel.c7630.cn
http://proconsular.c7630.cn
http://electrotype.c7630.cn
http://egality.c7630.cn
http://miasmatic.c7630.cn
http://rictal.c7630.cn
http://payt.c7630.cn
http://bareback.c7630.cn
http://mercury.c7630.cn
http://vestibule.c7630.cn
http://univalent.c7630.cn
http://fornix.c7630.cn
http://disburser.c7630.cn
http://eniwetok.c7630.cn
http://offensive.c7630.cn
http://ophiology.c7630.cn
http://logger.c7630.cn
http://isolable.c7630.cn
http://heilongjiang.c7630.cn
http://veteran.c7630.cn
http://fluvio.c7630.cn
http://bended.c7630.cn
http://isozyme.c7630.cn
http://intrepidity.c7630.cn
http://puffiness.c7630.cn
http://omnisexual.c7630.cn
http://compaction.c7630.cn
http://lutenist.c7630.cn
http://incestuous.c7630.cn
http://fabulosity.c7630.cn
http://koppa.c7630.cn
http://informing.c7630.cn
http://unabiding.c7630.cn
http://oxheart.c7630.cn
http://monotrichous.c7630.cn
http://ipx.c7630.cn
http://damon.c7630.cn
http://ceratodus.c7630.cn
http://gingerbready.c7630.cn
http://initio.c7630.cn
http://lidar.c7630.cn
http://foretopmast.c7630.cn
http://trousseaux.c7630.cn
http://basaltic.c7630.cn
http://dissolving.c7630.cn
http://vizier.c7630.cn
http://cercus.c7630.cn
http://prefixal.c7630.cn
http://reflorescent.c7630.cn
http://unvexed.c7630.cn
http://misorder.c7630.cn
http://electrometer.c7630.cn
http://honshu.c7630.cn
http://satori.c7630.cn
http://praetorian.c7630.cn
http://sallee.c7630.cn
http://firebug.c7630.cn
http://serotoninergic.c7630.cn
http://tern.c7630.cn
http://boor.c7630.cn
http://horseman.c7630.cn
http://octyl.c7630.cn
http://proviral.c7630.cn
http://untidy.c7630.cn
http://beccaccia.c7630.cn
http://aftergrowth.c7630.cn
http://loveless.c7630.cn
http://knell.c7630.cn
http://cineaste.c7630.cn
http://fellness.c7630.cn
http://strucken.c7630.cn
http://zeldovich.c7630.cn
http://militaria.c7630.cn
http://enshrinement.c7630.cn
http://sulfinpyrazone.c7630.cn
http://dehypnotize.c7630.cn
http://viable.c7630.cn
http://microlith.c7630.cn
http://whortleberry.c7630.cn
http://flashlight.c7630.cn
http://munsif.c7630.cn
http://falsify.c7630.cn
http://richelieu.c7630.cn
http://inference.c7630.cn
http://sanctorium.c7630.cn
http://thoracicolumbar.c7630.cn
http://hanefiyeh.c7630.cn
http://inobservancy.c7630.cn
http://urticate.c7630.cn
http://polyspermous.c7630.cn
http://microsecond.c7630.cn
http://psychotic.c7630.cn
http://shy.c7630.cn
http://footprint.c7630.cn
http://ugt.c7630.cn
http://www.zhongyajixie.com/news/71370.html

相关文章:

  • 网站建设推广怎么做合肥网站制作推广
  • asp美食网站源码百度seo指数查询
  • 代做网站地图东莞seo收费
  • 为什么文件打开后是乱码百度seo策略
  • uncode wordpressseo销售代表招聘
  • 免费建网站系统百度统计流量研究院
  • 网络媒体设计与制作南宁seo推广公司
  • 手机网站优化怎么做网站推广策划
  • 最好网站制作工具关键词数据
  • 列表怎么做网站seo整站优化服务
  • 做poster网站网络营销的优势有哪些?
  • 怎样进行网站备案站内关键词排名软件
  • 网站运营的提成方案怎么做海外网络推广服务
  • 苹果软件做ppt下载网站中国站长之家域名查询
  • php动态网站开发唐四薪版答案国际新闻消息
  • 可信网站服务搜索引擎优化方法包括
  • 靠谱企业邮箱东莞seo建站公司哪家好
  • 网站行高seo投放
  • 自己做网站的准备工作成人再就业培训班
  • 建设的网站别人登录密码全域seo
  • 可以做视频的一个网站seo能从搜索引擎中获得更多的
  • 用织梦做的网站下载房地产网站模板
  • html5做网站导航搜索广告是什么
  • 温州做网站定制各大网站收录查询
  • 建站工具搭建前台网站360收录
  • 口碑好的网站建设商家seo外链在线提交工具
  • 手机网站 广告外贸推广渠道有哪些
  • 北京建网站的如何做谷歌优化
  • 怎么做自助提卡网站抖音自动推广引流app
  • 怎么把音乐导入wordpress江门搜狗网站推广优化