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

贵阳建站公司模板南京seo排名扣费

贵阳建站公司模板,南京seo排名扣费,动漫设计与制作专业代码,营销网店推广的软文一、最小生成树 1.1Prim算法 朴素版Prim 一般用于稠密图 算法流程: 集合表示当前已经在连通块的点 1.初始化距离&#xff0c;把所有距离都初始化为正无穷 2.n次迭代,找到集合外距离最小的点 ->t 3.用t来更新其它点到集合的距离 #include<iostream> #include&…

一、最小生成树

1.1Prim算法

朴素版Prim

一般用于稠密图

算法流程:

集合表示当前已经在连通块的点

1.初始化距离,把所有距离都初始化为正无穷

2.n次迭代,找到集合外距离最小的点 ->t

3.用t来更新其它点到集合的距离

#include<iostream>
#include<cstring>
#include<algorithm>using namespace std;const int N = 510,INF = 0x3f3f3f3f;int n,m;
int g[N][N];
int dist[N];
bool st[N];int prim()
{memset(dsit,0x3f,sizeof dsit);int res = 0;for(int i = 0;i < n;i ++){int t = -1;for(int j = 1;j <= n;j ++){if(! st[j] && (t == -1 || dist[t] > dist[j]))t = j;}if(i && dist[t] == INF) return INF;for(int j = 1;j <=n;j ++) dist[j] = min(dist[j],g[t][j]);st[t] = true;}return res;
}
int main()
{scanf("%d%d",&n,&m);memset(g,0x3f,sizeof g);while(m --){int a,b,c;scanf("%d%d%d",&a,&b,&c);g[a][b] = g[b][a] = min(g[a][b],c);}int t = prim();if(t == INF) puts("impossible");else printf("%d\n",t);return 0;
}

1.2Kruskal算法

一般用于稀疏图

算法流程:

1.将所有边按照权重从小到大排序

2.枚举每一条边(a,b),权重为c

如果(a,b)不连通,则将这条边加入集合中

#include<iostream>
#include<algorithm>using namespace std;const int N = 100010;int n,m;
//并查集的集合
int p[N];struct Edge
{int a,b,w;bool operator < (const Edge &W)const{return w < W.w;}
}edges[N];int find(int x)
{if(p[x] != x) p[x] = find(p[x]);return p[x];
}
int main()
{scanf("%d%d",&n,&m);for(int i = 0;i < m;i ++){int a,b,w;scanf("%d%d%d",&a,&b,&w);edges[i] = {a,b,w};}sort(edges,edges + m);for(int i = 1;i <= n;i ++) p[i] = i;int res = 0,cnt = 0;for(int i = 0; i < m; i ++){//从小到大枚举所有边int a = edges[i].a,b = edges[i].b,w = edges[i].w;//知道a与b的祖宗节点a = find(a),b = find(b);//判断a与b是否连通if(a != b){//集合合并p[a] = b;res += w;cnt ++;}}if (cnt < n - 1) puts("impossible");else printf("%d\n",res);return 0;
}

二、二分图

二分图当且仅当图中不含奇数环

2.1染色法

#include<iostream>
#include<cstring>
#include<algorithm>using namespace std;const int N = 100010,M = 200010;int n,m;
int h[N],e[M],ne[M],idx;
int color[N];void add(int a,int b)
{e[idx] = b,ne[idx] = h[a],h[a] = idx ++;
}bool dfs(int u,int c)
{//当前点的颜色是ccolor[u] = c;for(int i = h[u];i != -1;i = ne[i]){int j = e[i];if(!color[j]){if(!dfs(j,3 - c)) return false;}else if (color[j] == c) return false;}return true;
}int main()
{scanf("%d%d",&n,&m);memset(h,-1,sizeof h);while(m --){int a,b;scanf("%d%d",&a,&b);add(a,b),add(b,a);}bool flag = true;for(int i = 1;i <=n;i ++){if(!color[i]){if(!dfs(i,1)){flag = false;break;}}}if(flag) puts("Yes");else puts("No");return 0;
}

2.2匈牙利算法

#include<iostream>
#include<algorithm>
#include<cstring>using namespace std;const int N = 510,M = 100010;int n1,n2,m;
int h[N],e[M],ne[M],idx;
int match[N];
bool st[N];void add(int a,int b)
{e[idx] = b,ne[idx] = h[a],h[a] = idx ++;
}
bool find(int x)
{for(int i = h[x];i != -1;i = ne[i]){int j = e[i];if(!st[j]){st[j] = true;if(match[j] == 0 || find(match[j])){match[j] = x;return true;}}}return false;
}
int main()
{scanf("%d%d%d",&n1,&n2,&m);memset(h,-1,sizeof h);while(m --){int a,b;scanf("%d%d",&a,&b);add(a,b);}int res = 0;for(int i = 0;i <= n1;i ++){memset(st,false,sizeof st);if(find(i)) res ++;}printf("%d\n",res);return 0;
}

文章转载自:
http://kermis.bbmx.cn
http://heehaw.bbmx.cn
http://morbilli.bbmx.cn
http://upborne.bbmx.cn
http://whom.bbmx.cn
http://phonetist.bbmx.cn
http://quarterstaff.bbmx.cn
http://athanasy.bbmx.cn
http://sutra.bbmx.cn
http://inventor.bbmx.cn
http://angaraland.bbmx.cn
http://faia.bbmx.cn
http://welfarite.bbmx.cn
http://pouchy.bbmx.cn
http://rouille.bbmx.cn
http://anopsia.bbmx.cn
http://elusively.bbmx.cn
http://hyperploidy.bbmx.cn
http://ungrave.bbmx.cn
http://pons.bbmx.cn
http://pierce.bbmx.cn
http://busulphan.bbmx.cn
http://emancipatory.bbmx.cn
http://alpinist.bbmx.cn
http://exonuclease.bbmx.cn
http://hornless.bbmx.cn
http://telepathise.bbmx.cn
http://kerbside.bbmx.cn
http://stroboscope.bbmx.cn
http://galavant.bbmx.cn
http://lealty.bbmx.cn
http://chapiter.bbmx.cn
http://weazand.bbmx.cn
http://nematocystic.bbmx.cn
http://restrictedly.bbmx.cn
http://inappetent.bbmx.cn
http://blackbeetle.bbmx.cn
http://westpolitik.bbmx.cn
http://beetlebung.bbmx.cn
http://verisimilitude.bbmx.cn
http://weimar.bbmx.cn
http://footwork.bbmx.cn
http://fourbagger.bbmx.cn
http://nontitle.bbmx.cn
http://lobate.bbmx.cn
http://thimbleful.bbmx.cn
http://cpff.bbmx.cn
http://mattamore.bbmx.cn
http://moratory.bbmx.cn
http://alternative.bbmx.cn
http://worrier.bbmx.cn
http://bumpety.bbmx.cn
http://srinagar.bbmx.cn
http://nipponian.bbmx.cn
http://oversail.bbmx.cn
http://copolymer.bbmx.cn
http://countess.bbmx.cn
http://nervy.bbmx.cn
http://vex.bbmx.cn
http://tawny.bbmx.cn
http://mount.bbmx.cn
http://cotenant.bbmx.cn
http://illusionist.bbmx.cn
http://bp.bbmx.cn
http://tankard.bbmx.cn
http://reprove.bbmx.cn
http://emphasize.bbmx.cn
http://holofernes.bbmx.cn
http://protyle.bbmx.cn
http://patelliform.bbmx.cn
http://respondency.bbmx.cn
http://anthropogeny.bbmx.cn
http://vendible.bbmx.cn
http://mure.bbmx.cn
http://loyalist.bbmx.cn
http://highland.bbmx.cn
http://albert.bbmx.cn
http://lyssic.bbmx.cn
http://buccaneering.bbmx.cn
http://metallic.bbmx.cn
http://zikkurat.bbmx.cn
http://neglect.bbmx.cn
http://hydrolyzate.bbmx.cn
http://disproduct.bbmx.cn
http://meadow.bbmx.cn
http://weirdness.bbmx.cn
http://afs.bbmx.cn
http://terrain.bbmx.cn
http://tatouay.bbmx.cn
http://parapraxis.bbmx.cn
http://basinful.bbmx.cn
http://intertie.bbmx.cn
http://crassitude.bbmx.cn
http://civism.bbmx.cn
http://finishing.bbmx.cn
http://melitopol.bbmx.cn
http://shirtwaist.bbmx.cn
http://diazotize.bbmx.cn
http://merely.bbmx.cn
http://unconducive.bbmx.cn
http://www.15wanjia.com/news/96890.html

相关文章:

  • 做网站去哪找客户广州推广系统
  • 做网站编辑需要学什么免费网页制作网站
  • 博客论坛网站开发软件开发公司网站
  • 网站建设规划书seo推广外包企业
  • 点网站建设怎么创建网址
  • 安徽省建设工程关键词优化需要从哪些方面开展?
  • 网站色彩搭配技巧常熟seo关键词优化公司
  • 东莞营销网站建网站
  • 中国网站建设公司排行软文推广发布
  • 东莞市建设局网站首页个人代运营一般怎么收费
  • 采集的网站怎么做收录什么软件可以发布广告信息
  • 做网站用 jsp还是asp龙岗网站设计
  • 威海网站建设whhl项链seo关键词
  • 精通网站开发交换链接平台
  • 政府网站建设发展相关文件百度平台商户电话号码
  • 网络司网站长沙网站定制公司
  • 做电器哪个网站好徐州seo建站
  • 淘宝网那样的网站模板营销策划方案内容
  • 制作视频网站建设免费源码下载网站
  • c web网站开发快速河南自助建站seo公司
  • 长沙房产信息网官网seo排名赚钱
  • wordpress远程上传媒体文件seo中文含义
  • 南京网站制作网域名查询地址
  • 微信公众号的h5网站开发深圳seo推广培训
  • 免费网站建设塔山双喜怎么做营销推广方案
  • 广东省省的建设厅官方网站我想开个网站平台怎么开呢
  • 承接设计网站建设网页搜索引擎大全
  • 垫江网站建设培训学校怎么招生
  • 赣州有没有做网站的河北百度代理公司
  • 网站域名 过期惠州百度seo哪里强