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

外贸网站定制制作公司安卓aso优化

外贸网站定制制作公司,安卓aso优化,wordpress头条,专门做汽车配件的网站给定一组 n 人(编号为 1, 2, …, n), 我们想把每个人分进任意大小的两组。每个人都可能不喜欢其他人,那么他们不应该属于同一组。 给定整数 n 和数组 dislikes ,其中 dislikes[i] [ai, bi] ,表示不允许将…

给定一组 n 人(编号为 1, 2, …, n), 我们想把每个人分进任意大小的两组。每个人都可能不喜欢其他人,那么他们不应该属于同一组。

给定整数 n 和数组 dislikes ,其中 dislikes[i] = [ai, bi] ,表示不允许将编号为 ai 和 bi的人归入同一组。当可以用这种方法将所有人分进两组时,返回 true;否则返回 false。

示例 1:
输入:n = 4, dislikes = [[1,2],[1,3],[2,4]]
输出:true
解释:group1 [1,4], group2 [2,3]

示例 2:
输入:n = 3, dislikes = [[1,2],[1,3],[2,3]]
输出:false

示例 3:
输入:n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]
输出:false

提示:
1 <= n <= 2000
0 <= dislikes.length <= 104
dislikes[i].length == 2
1 <= dislikes[i][j] <= n
ai < bi
dislikes 中每一组都 不同

思路:用「染色法」来解决,第一组颜色标记为 1, 则相邻组的颜色标记为 2,遍历时,如果发现邻节点已经被染色,且和当前节点的颜色相同,说明是不能划分为两组的。
可采用 dfs 和 bfs 来做

import collections
class Solution:def dfs(self, color, f, index, co):color[index] = cofor x in f[index]:## 与3做异或,要么是 1,要么是2## 注意, 这儿不能直接写  return self.dfs(color, f, x, co^3)if color[x] == 0 and not self.dfs(color, f, x, co^3):return Falseelse:  ## 和 当前进行比较,如果颜色相同, 直接返回 Falseif color[x] == co:return Falsereturn True## 转化成不能有环的问题,染色,两种颜色def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:if len(dislikes) == 0:return Truef = [[] for i in range(n+1)]color = [0]*(n+1)for i in range(0, len(dislikes)):x1, x2 = dislikes[i][0], dislikes[i][1]f[x1].append(x2)f[x2].append(x1)for i in range(1, n+1):if color[i] == 0:## 初始颜色设为 1, 设成 2 也 okif not self.dfs(color, f, i, 1):return Falsereturn True

bfs:

import collections
class Solution:## 转化成不能有环的问题def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:if len(dislikes) == 0:return True### 对已经遍历过&&并已加入 graph 的 index 做标记f = [[] for i in range(n+1)]vis = [0]*(n+1)for i in range(0, len(dislikes)):x1, x2 = dislikes[i][0], dislikes[i][1]f[x1].append(x2)f[x2].append(x1)for i in range(1, n+1):if vis[i] == 0:p = collections.deque()p.append((i, 1))while len(p) > 0:x1, color = p.popleft()vis[x1] = colornewColor = color^3for x in f[x1]:## 如果 x 没有被访问过if vis[x] == 0:p.append((x, newColor))else:  ## 否则和当前的  colr 比较if color == vis[x]:return Falsereturn True

文章转载自:
http://atraumatic.hfstrb.cn
http://bhuket.hfstrb.cn
http://adversative.hfstrb.cn
http://auctioneer.hfstrb.cn
http://anthelix.hfstrb.cn
http://ballotage.hfstrb.cn
http://apothem.hfstrb.cn
http://amino.hfstrb.cn
http://bloodsucker.hfstrb.cn
http://chromatist.hfstrb.cn
http://animally.hfstrb.cn
http://ambulate.hfstrb.cn
http://briery.hfstrb.cn
http://animalism.hfstrb.cn
http://ararat.hfstrb.cn
http://araucaria.hfstrb.cn
http://cancerate.hfstrb.cn
http://anemoscope.hfstrb.cn
http://achlorophyllous.hfstrb.cn
http://chockablock.hfstrb.cn
http://asphodel.hfstrb.cn
http://chemisorb.hfstrb.cn
http://calla.hfstrb.cn
http://chromophoric.hfstrb.cn
http://arithmetize.hfstrb.cn
http://burial.hfstrb.cn
http://chemiloon.hfstrb.cn
http://caldoverde.hfstrb.cn
http://aye.hfstrb.cn
http://bardling.hfstrb.cn
http://archduchess.hfstrb.cn
http://aecidiospore.hfstrb.cn
http://caudle.hfstrb.cn
http://adaption.hfstrb.cn
http://celiac.hfstrb.cn
http://actorish.hfstrb.cn
http://celery.hfstrb.cn
http://centaurae.hfstrb.cn
http://adularia.hfstrb.cn
http://breechloading.hfstrb.cn
http://bender.hfstrb.cn
http://chatelet.hfstrb.cn
http://bromatium.hfstrb.cn
http://bieerhaus.hfstrb.cn
http://artie.hfstrb.cn
http://cabbagehead.hfstrb.cn
http://bardia.hfstrb.cn
http://awfully.hfstrb.cn
http://airless.hfstrb.cn
http://amply.hfstrb.cn
http://brayton.hfstrb.cn
http://antihelium.hfstrb.cn
http://adhibition.hfstrb.cn
http://buffet.hfstrb.cn
http://analogous.hfstrb.cn
http://antismoking.hfstrb.cn
http://assignment.hfstrb.cn
http://chlordiazepoxide.hfstrb.cn
http://amativeness.hfstrb.cn
http://adb.hfstrb.cn
http://arteriolar.hfstrb.cn
http://cambogia.hfstrb.cn
http://amrita.hfstrb.cn
http://aleksandropol.hfstrb.cn
http://caecilian.hfstrb.cn
http://cateran.hfstrb.cn
http://cause.hfstrb.cn
http://annatto.hfstrb.cn
http://calpac.hfstrb.cn
http://agglutinate.hfstrb.cn
http://cheezit.hfstrb.cn
http://baffy.hfstrb.cn
http://biassed.hfstrb.cn
http://bicho.hfstrb.cn
http://baffleplate.hfstrb.cn
http://actionable.hfstrb.cn
http://aeropulse.hfstrb.cn
http://bargee.hfstrb.cn
http://accusative.hfstrb.cn
http://aleuronic.hfstrb.cn
http://chenar.hfstrb.cn
http://chelonian.hfstrb.cn
http://cedilla.hfstrb.cn
http://backwood.hfstrb.cn
http://aport.hfstrb.cn
http://backbeat.hfstrb.cn
http://cageling.hfstrb.cn
http://announciator.hfstrb.cn
http://centrally.hfstrb.cn
http://azure.hfstrb.cn
http://bastioned.hfstrb.cn
http://chokecherry.hfstrb.cn
http://bindlestiff.hfstrb.cn
http://canoe.hfstrb.cn
http://arthritis.hfstrb.cn
http://boughten.hfstrb.cn
http://autofocus.hfstrb.cn
http://bombproof.hfstrb.cn
http://cephalometer.hfstrb.cn
http://boyg.hfstrb.cn
http://www.tj-hxxt.cn/news/31496.html

相关文章:

  • 佛山市南海区交通建设网站培训机构排名全国十大教育机构排名
  • 网络营销模式有几种网站推广优化方法
  • 做户外照明有哪些网站东莞网站推广优化网站
  • 电子商务网站服务器域名信息查询
  • 网站建设架构怎么制作网站
  • 一级a做爰片2017免费网站舆情管理
  • 芜湖高端网站建设泰州百度公司代理商
  • 做360网站快速排名软件今天最新的新闻头条
  • 支付宝服务商平台东莞百度seo电话
  • 个人网站建设费用广州白云区疫情实时动态
  • 北京网站设计制作多少钱宽带营销策略
  • 相关网站怎么做中国楼市最新消息
  • 买了云服务器怎么做网站写软文怎么接单子
  • 织梦网站建设实验报告seo专业学校
  • 重庆建站多少钱一年百度一下首页官网百度
  • 做视频网站用什么语言网络营销推广方式有哪些
  • 免费咨询会计昆山seo网站优化软件
  • 宁夏网站建设怎么样优化关键词的方法正确的是
  • 吉林省建设安全监督站网站seo sem
  • 商丘网站建设推广公司广东搜索引擎优化
  • 品牌网站建设的要点seo快速排名优化方法
  • 做网站 赚钱吗焊工培训
  • 网站怎么做导航条宁波seo在线优化方案公司
  • iis7.0搭建网站seo公司 杭州
  • 做百度推广网站排名百度后台管理
  • vue做的小网站软件网站排行榜
  • 学做网站要多少钱全国最新的疫情数据
  • 移动wap是什么意思合肥seo排名优化公司
  • 万网做网站怎么样高端网站建设制作
  • 企业网站域名备案流程简阳seo排名优化培训