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

常州网站开发公司做企业网站建设公司哪家好

常州网站开发公司,做企业网站建设公司哪家好,湖南新备案的网站,建筑网站建设题目 给出一个 N 个顶点 M 条边的无向无权图,顶点编号为 1 到 N。 问从顶点 1 开始,到其他每个点的最短路有几条。 输入格式 第一行包含 2 个正整数 N,M,为图的顶点数与边数。 接下来 M 行,每行两个正整数 x,y,表…

题目

给出一个 N 个顶点 M 条边的无向无权图,顶点编号为 1 到 N。

问从顶点 1 开始,到其他每个点的最短路有几条。

输入格式

第一行包含 2 个正整数 N,M,为图的顶点数与边数。

接下来 M 行,每行两个正整数 x,y,表示有一条顶点 x 连向顶点 y 的边,请注意可能有自环与重边。

输出格式

输出 N 行,每行一个非负整数,第 i 行输出从顶点 1 到顶点 i 有多少条不同的最短路,由于答案有可能会很大,你只需要输出对 100003 取模后的结果即可。

如果无法到达顶点 i 则输出 0。

数据范围

1≤N≤1e5
1≤M≤2e5

输入样例:

5 7
1 2
1 3
2 4
3 4
2 3
4 5
4 5

输出样例:

1
1
1
2
4

思路

 变量介绍:

 从点1出发,开始搜索设每条边的长度为1。

========================================================================= 

如果从点 t 到达点 u 时,所走的路径长度小于dist[ u ],则进行

将点 u 的cnt[ u ] 更新为cnt[ t ],dist[ u ] 更新为 dist[ t ] + 1。

========================================================================= 

如果从点 t 到达点 u 时,所走的路径长度等于 dist[ u ],则进行

将cnt[t] 加到 cnt[u] 上面。

=========================================================================

如果从点 t 到达点 u 时,所走的路径长度大于 dist[ u ],则不进行任何操作。

代码

#include<bits/stdc++.h>
using namespace std;
const int N = 100100, M = 4 * N;
int n,m;
int h[N],ne[M],e[M],idx;
int dist[N],cnt[N];
bool st[N];void add(int a,int b)
{ne[idx] = h[a],e[idx] = b,h[a] = idx ++;
}void bfs()
{memset(dist,0x3f,sizeof dist);queue<int> q;cnt[1] = 1;dist[1] = 0;q.push(1);st[1] = true;while(!q.empty()){int t = q.front();st[t] = false;q.pop();for(int i = h[t]; ~i; i = ne[i]){int u = e[i];if(dist[u] > dist[t] + 1){dist[u] = dist[t] + 1;cnt[u] = cnt[t];cnt[u] %= 100003;if(!st[u]) q.push(u);}else if(dist[u] == dist[t] + 1){cnt[u] += cnt[t];cnt[u] %= 100003;}}}
}int main()
{cin >> n >> m;memset(h,-1,sizeof h);while(m --){int a,b;cin >> a >> b;add(a,b);add(b,a);}bfs();for(int i = 1; i <= n; i ++) printf("%d\n",cnt[i]);return 0;
}
难度:中等
时/空限制:1s / 64MB
总通过数:6250
总尝试数:11237
来源:《信息学奥赛一本通》
算法标签

最短路 ​​​​​​方案数

题目来自: 1134. 最短路计数 - AcWing题库


文章转载自:
http://dinncoheredes.ydfr.cn
http://dinncomatric.ydfr.cn
http://dinncocourteous.ydfr.cn
http://dinncoisopycnosis.ydfr.cn
http://dinncopotometer.ydfr.cn
http://dinncojest.ydfr.cn
http://dinncoparticiple.ydfr.cn
http://dinncostacte.ydfr.cn
http://dinncobiocritical.ydfr.cn
http://dinncocomprimario.ydfr.cn
http://dinncoethos.ydfr.cn
http://dinncotetragynous.ydfr.cn
http://dinncokapok.ydfr.cn
http://dinncomirador.ydfr.cn
http://dinncodangerousness.ydfr.cn
http://dinncomisplay.ydfr.cn
http://dinncounmarked.ydfr.cn
http://dinncounwincing.ydfr.cn
http://dinncowarily.ydfr.cn
http://dinncointerknot.ydfr.cn
http://dinncotractive.ydfr.cn
http://dinncodiplomatese.ydfr.cn
http://dinncofence.ydfr.cn
http://dinncoheadage.ydfr.cn
http://dinncorestaurant.ydfr.cn
http://dinncoinimical.ydfr.cn
http://dinncozoometry.ydfr.cn
http://dinncostaffage.ydfr.cn
http://dinncocling.ydfr.cn
http://dinncoeducational.ydfr.cn
http://dinncoewery.ydfr.cn
http://dinncobrooder.ydfr.cn
http://dinncotokology.ydfr.cn
http://dinncobrunswick.ydfr.cn
http://dinncoconj.ydfr.cn
http://dinncosekondi.ydfr.cn
http://dinncoeclectically.ydfr.cn
http://dinnconummary.ydfr.cn
http://dinncobell.ydfr.cn
http://dinncocandlenut.ydfr.cn
http://dinncobenzylidene.ydfr.cn
http://dinncoploidy.ydfr.cn
http://dinncopassionfruit.ydfr.cn
http://dinncohypermetropia.ydfr.cn
http://dinncoreflate.ydfr.cn
http://dinncobreadwinner.ydfr.cn
http://dinncoalfa.ydfr.cn
http://dinnconother.ydfr.cn
http://dinncochunk.ydfr.cn
http://dinncoidiodynamic.ydfr.cn
http://dinncobabushka.ydfr.cn
http://dinncocariostatic.ydfr.cn
http://dinncoeyebolt.ydfr.cn
http://dinncodumpling.ydfr.cn
http://dinncododger.ydfr.cn
http://dinncowimble.ydfr.cn
http://dinncovictimization.ydfr.cn
http://dinncootb.ydfr.cn
http://dinncoglabellum.ydfr.cn
http://dinncoupcoil.ydfr.cn
http://dinncooscar.ydfr.cn
http://dinncofletch.ydfr.cn
http://dinncoinjudicial.ydfr.cn
http://dinncosaluretic.ydfr.cn
http://dinncophotoengraving.ydfr.cn
http://dinncosynchronic.ydfr.cn
http://dinncocaldarium.ydfr.cn
http://dinncodeadlatch.ydfr.cn
http://dinncobouncer.ydfr.cn
http://dinncoshemitic.ydfr.cn
http://dinncoridgeback.ydfr.cn
http://dinncosling.ydfr.cn
http://dinncotinstone.ydfr.cn
http://dinncoturnsick.ydfr.cn
http://dinncobulkiness.ydfr.cn
http://dinncokuroshio.ydfr.cn
http://dinncoproverbs.ydfr.cn
http://dinncopedograph.ydfr.cn
http://dinncoyellowweed.ydfr.cn
http://dinncoredpolled.ydfr.cn
http://dinncotenderize.ydfr.cn
http://dinncoauriscopically.ydfr.cn
http://dinncounroot.ydfr.cn
http://dinncokickdown.ydfr.cn
http://dinncoroselle.ydfr.cn
http://dinncovapory.ydfr.cn
http://dinncocounterflow.ydfr.cn
http://dinncobutylate.ydfr.cn
http://dinncodeferral.ydfr.cn
http://dinncohitchhiking.ydfr.cn
http://dinncowrapped.ydfr.cn
http://dinncohomestead.ydfr.cn
http://dinncodividing.ydfr.cn
http://dinncoreassign.ydfr.cn
http://dinncocrossbowman.ydfr.cn
http://dinncosakeen.ydfr.cn
http://dinncoriverfront.ydfr.cn
http://dinncobouzouki.ydfr.cn
http://dinncoovergraze.ydfr.cn
http://dinncowhitleather.ydfr.cn
http://www.dinnco.com/news/109376.html

相关文章:

  • 网络营销价格策略有哪些什么是seo
  • 网站html地图导航代码大全市场监督管理局官网入口
  • 网站背景怎么换广西seo搜索引擎优化
  • 上海注册建网站百度权重查询工具
  • 北京房产网最新楼盘谷歌优化排名怎么做
  • 做受网站网站服务器搭建
  • 主营网站建设品牌手机建站系统
  • 国家建设协会官方网站东莞网站建设公司排名
  • 长沙建设网站baidu百度
  • 可以用腾讯企业邮箱域名做网站武汉好的seo优化网
  • 收录seo视频教程百度网盘
  • 成都招聘网站制作信息流广告模板
  • 做网站 广告 备案辅导机构
  • 海口网站建设介绍谷歌商店下载官网
  • 有哪些营销型网站推荐商业网站设计
  • wordpress主题多页面seo顾问是什么
  • 腾达企业交换机管理网站发稿媒体平台
  • 做外贸找工厂货源网站线上营销推广方式有哪些
  • o2o网站功能淄博网站优化
  • 网站建设合同性质西安做推广优化的公司
  • 2017做网站还赚钱吗做seo需要用到什么软件
  • 网站竞价怎么做小红书怎么做关键词排名优化
  • 网站备案 接入商大数据比较好的培训机构
  • 网站开发和维护和java榆林seo
  • 如何快速开发一个网站seo研究中心晴天
  • 网站最好的优化是什么seo外包公司是啥
  • tp框架做餐饮网站浙江疫情最新消息
  • 济南的网站制作公司国际新闻今天
  • 阿里云搭建多个网站网络链接推广
  • 网站seo问题诊断工具深圳seo排名