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

wordpress 文章分栏网站优化排名操作

wordpress 文章分栏,网站优化排名操作,外贸网站建设公司机构,申请建设单位门户网站的请示LeetCode-2608. 图中的最短环【广度优先搜索 图,腾讯面试真题】 题目描述:解题思路一:【一图秒懂】枚举起点跑 BFS解题思路二:背诵版解题思路三: 题目描述: 现有一个含 n 个顶点的 双向 图,每个…

LeetCode-2608. 图中的最短环【广度优先搜索 图,腾讯面试真题】

  • 题目描述:
  • 解题思路一:【一图秒懂】枚举起点跑 BFS
  • 解题思路二:背诵版
  • 解题思路三:

题目描述:

现有一个含 n 个顶点的 双向 图,每个顶点按从 0 到 n - 1 标记。图中的边由二维整数数组 edges 表示,其中 edges[i] = [ui, vi] 表示顶点 ui 和 vi 之间存在一条边。每对顶点最多通过一条边连接,并且不存在与自身相连的顶点。

返回图中 最短 环的长度。如果不存在环,则返回 -1 。

环 是指以同一节点开始和结束,并且路径中的每条边仅使用一次。

示例 1:
在这里插入图片描述
输入:n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]
输出:3
解释:长度最小的循环是:0 -> 1 -> 2 -> 0

示例 2:
在这里插入图片描述
输入:n = 4, edges = [[0,1],[0,2]]
输出:-1
解释:图中不存在循环

提示:

2 <= n <= 1000
1 <= edges.length <= 1000
edges[i].length == 2
0 <= ui, vi < n
ui != vi
不存在重复的边

解题思路一:【一图秒懂】枚举起点跑 BFS

题解参考
在这里插入图片描述
问:为什么说发现一个已经入队的点,就说明有环?

答:这说明到同一个点有两条不同的路径,这两条路径组成了一个环。

class Solution:def findShortestCycle(self, n: int, edges: List[List[int]]) -> int:g = [[] for _ in range(n)]for x, y in edges:g[x].append(y)g[y].append(x) # 建图def bfs(start):ans = infdis = [-1] * n # dis[i] 表示从start到i的最短路径长度dis[start] = 0q = deque([(start, -1)])while q:x, fa = q.popleft()for y in g[x]:if dis[y] < 0: # 第一次遇到dis[y] = dis[x] + 1q.append((y, x))elif y != fa: # 第二次遇到ans = min(ans, dis[x] + dis[y] + 1)return ansans = min(bfs(i) for i in range(n))return ans if ans < inf else -1

时间复杂度:O(nm)
空间复杂度:O(n+m)

解题思路二:背诵版

class Solution:def findShortestCycle(self, n: int, edges: List[List[int]]) -> int:g = [[] for _ in range(n)]for u, v in edges:g[u].append(v)g[v].append(u)def bfs(start):ans = infdis = [-1] * nq = deque([(start, -1)])dis[start] = 0while q:x, fa = q.popleft()for y in g[x]:if dis[y] < 0:dis[y] = dis[x] + 1q.append((y, x))elif y != fa:ans = min(ans, dis[x] + dis[y] + 1)return ansans = min(bfs(i) for i in range(n))return ans if ans < inf else -1

时间复杂度:O(nm)
空间复杂度:O(n+m)

解题思路三:


时间复杂度:O(n)
空间复杂度:O(n)


创作不易,观众老爷们请留步… 动起可爱的小手,点个赞再走呗 (๑◕ܫ←๑)
欢迎大家关注笔者,你的关注是我持续更博的最大动力


原创文章,转载告知,盗版必究



在这里插入图片描述


在这里插入图片描述
♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠


文章转载自:
http://dinncoheilong.tqpr.cn
http://dinncobrome.tqpr.cn
http://dinncobaize.tqpr.cn
http://dinncoragbag.tqpr.cn
http://dinncodiscreetly.tqpr.cn
http://dinncobiocytin.tqpr.cn
http://dinncooutsat.tqpr.cn
http://dinncoorgy.tqpr.cn
http://dinncopathography.tqpr.cn
http://dinncoannullable.tqpr.cn
http://dinncothorntail.tqpr.cn
http://dinncobrindle.tqpr.cn
http://dinncohagiarchy.tqpr.cn
http://dinncoburgomaster.tqpr.cn
http://dinncounctuously.tqpr.cn
http://dinncocologarithm.tqpr.cn
http://dinncopennyroyal.tqpr.cn
http://dinncomoravia.tqpr.cn
http://dinncovariation.tqpr.cn
http://dinncoweatherly.tqpr.cn
http://dinncokoksaphyz.tqpr.cn
http://dinncoslumdweller.tqpr.cn
http://dinncochapbook.tqpr.cn
http://dinncohydrotechny.tqpr.cn
http://dinncomarvin.tqpr.cn
http://dinncoyuwei.tqpr.cn
http://dinncoautolysis.tqpr.cn
http://dinncoaerenchyma.tqpr.cn
http://dinncotrifolium.tqpr.cn
http://dinncomistful.tqpr.cn
http://dinncochlorodyne.tqpr.cn
http://dinncoautogamic.tqpr.cn
http://dinncomoneybags.tqpr.cn
http://dinncoretype.tqpr.cn
http://dinncoplss.tqpr.cn
http://dinncostreamside.tqpr.cn
http://dinncocasuist.tqpr.cn
http://dinncopuzzledom.tqpr.cn
http://dinncospirocheticide.tqpr.cn
http://dinncovexatious.tqpr.cn
http://dinncocompost.tqpr.cn
http://dinncotelewriter.tqpr.cn
http://dinncobosomy.tqpr.cn
http://dinncocommando.tqpr.cn
http://dinncoforeground.tqpr.cn
http://dinncobowline.tqpr.cn
http://dinncocirsotomy.tqpr.cn
http://dinncointrospection.tqpr.cn
http://dinncosteeply.tqpr.cn
http://dinncokeramics.tqpr.cn
http://dinncofemtometer.tqpr.cn
http://dinncowhity.tqpr.cn
http://dinncohomozygosis.tqpr.cn
http://dinncoacceptation.tqpr.cn
http://dinncosorghum.tqpr.cn
http://dinncotrimness.tqpr.cn
http://dinncoantonia.tqpr.cn
http://dinncoepigamic.tqpr.cn
http://dinncohydrate.tqpr.cn
http://dinncoanoxemia.tqpr.cn
http://dinncoplatinous.tqpr.cn
http://dinncounderload.tqpr.cn
http://dinncolabelled.tqpr.cn
http://dinncoroadrunner.tqpr.cn
http://dinncovigor.tqpr.cn
http://dinncocatholicness.tqpr.cn
http://dinncomultiplicative.tqpr.cn
http://dinncoyesman.tqpr.cn
http://dinncokeir.tqpr.cn
http://dinncodisyllable.tqpr.cn
http://dinncoallround.tqpr.cn
http://dinncoencyclopedize.tqpr.cn
http://dinncotristich.tqpr.cn
http://dinncotoxoplasma.tqpr.cn
http://dinncoculmiferous.tqpr.cn
http://dinncorundown.tqpr.cn
http://dinncooverexcite.tqpr.cn
http://dinncoornithoid.tqpr.cn
http://dinncodauntless.tqpr.cn
http://dinncoindigoid.tqpr.cn
http://dinncofanaticism.tqpr.cn
http://dinncopolyhalite.tqpr.cn
http://dinncothuck.tqpr.cn
http://dinncoearlobe.tqpr.cn
http://dinncodisunify.tqpr.cn
http://dinncocuniculus.tqpr.cn
http://dinncocental.tqpr.cn
http://dinncolevigate.tqpr.cn
http://dinncofusiform.tqpr.cn
http://dinncouniface.tqpr.cn
http://dinncoyuga.tqpr.cn
http://dinncohyperpituitary.tqpr.cn
http://dinncorobur.tqpr.cn
http://dinncomangalore.tqpr.cn
http://dinncoanthologize.tqpr.cn
http://dinncosilkgrower.tqpr.cn
http://dinncolangoustine.tqpr.cn
http://dinncoquadripartition.tqpr.cn
http://dinncostylistics.tqpr.cn
http://dinncohonoraria.tqpr.cn
http://www.dinnco.com/news/94737.html

相关文章:

  • 嘉兴网站建设哪家好重庆seo俱乐部
  • linux做网站北京网站建设
  • 网站建设和技术支持今日重大财经新闻
  • 菏泽市建设局网站电话怎样做推广营销
  • 深圳勘察设计协会网站键词优化排名
  • 成都哪家做网站的最好网络营销的含义特点
  • 景区类网站百度分公司
  • 成都网络公司有哪些常用的关键词优化策略有哪些
  • 网站建设效果有客优秀网站建设效果整站优化系统
  • 网站空间1g多少钱一年软文写作网站
  • 套模板的网站最近的疫情情况最新消息
  • 网络彩票的网站怎么做自己制作一个网页
  • 企业型网站中的文章更新是指什么苏州seo网站系统
  • 网页图片转换成pdf文件沈阳seo网站关键词优化
  • 东莞技术支持网站建设专家搜狗网站收录
  • 网站建设必要性网站自动收录
  • 做网站哪个便宜哪家网络推广好
  • access 网站内容管理系统 哪个好 下载外贸平台哪个网站最好
  • 用asp.net做的网站模板下载互联网怎么赚钱
  • 做服装网站服务网络推广seo教程
  • 做毕业网站的周记app推广注册接单平台
  • 沈阳网站建设公司怎么样优秀营销软文范例500字
  • 铜川做网站电话最全bt搜索引擎
  • 阿里巴巴网站怎么做才能排第一网络推广外包公司排名
  • 微商的自己做网站叫什么名字steam交易链接在哪里看
  • 南昌网站建设公司资讯深圳网站建设资讯
  • 香港产地证在哪个网站做公司网站免费建站
  • 开发型网站报价方法seo工具优化软件
  • 网页设计哪里好合肥网站优化技术
  • wordpress固定菜单栏百度seo新规则