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

昌平企业网站建设信阳网站推广公司

昌平企业网站建设,信阳网站推广公司,个人如何建立网站,如何推广自己的公司1466. 重新规划路线 中等 n 座城市,从 0 到 n-1 编号,其间共有 n-1 条路线。因此,要想在两座不同城市之间旅行只有唯一一条路线可供选择(路线网形成一颗树)。去年,交通运输部决定重新规划路线&#xff0c…

1466. 重新规划路线

中等

n 座城市,从 0n-1 编号,其间共有 n-1 条路线。因此,要想在两座不同城市之间旅行只有唯一一条路线可供选择(路线网形成一颗树)。去年,交通运输部决定重新规划路线,以改变交通拥堵的状况。

路线用 connections 表示,其中 connections[i] = [a, b] 表示从城市 ab 的一条有向路线。

今年,城市 0 将会举办一场大型比赛,很多游客都想前往城市 0 。

请你帮助重新规划路线方向,使每个城市都可以访问城市 0 。返回需要变更方向的最小路线数。

题目数据 保证 每个城市在重新规划路线方向后都能到达城市 0 。

示例 1:

img

输入:n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]
输出:3
解释:更改以红色显示的路线的方向,使每个城市都可以到达城市 0 。

示例 2:

img

输入:n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]
输出:2
解释:更改以红色显示的路线的方向,使每个城市都可以到达城市 0 。

示例 3:

输入:n = 3, connections = [[1,0],[2,0]]
输出:0

提示:

  • 2 <= n <= 5 * 10^4
  • connections.length == n-1
  • connections[i].length == 2
  • 0 <= connections[i][0], connections[i][1] <= n-1
  • connections[i][0] != connections[i][1]

BFS

class Solution {/**构件图时标志是正边还是反边,一次bfs如果是反边则需要res+1*/List<int[]>[] g;public int minReorder(int n, int[][] connections) {g = new ArrayList[n];Arrays.setAll(g, e -> new ArrayList<int[]>());for(int[] c : connections){int x = c[0], y = c[1];g[x].add(new int[]{y, -1}); // 1标志正边,-1标志反边g[y].add(new int[]{x, 1});}boolean[] vis = new boolean[n];Deque<Integer> dq = new ArrayDeque<>();dq.add(0);vis[0] = true;int res = 0;while(!dq.isEmpty()){int x = dq.pollLast();for(int[] q : g[x]){int y = q[0], dir = q[1];if(vis[y]) continue;vis[y] = true;if(dir == -1) res += 1;dq.addFirst(y);}}return res;}
}

DFS

class Solution {   List<int[]>[] g;int res = 0;boolean[] vis;public int minReorder(int n, int[][] connections) {g = new ArrayList[n];Arrays.setAll(g, e -> new ArrayList<int[]>());for(int[] c : connections){int x = c[0], y = c[1];g[x].add(new int[]{y, -1}); // 1标志正边,-1标志反边g[y].add(new int[]{x, 1});}vis = new boolean[n];dfs(0, -1);return res;}public void dfs(int x, int fa){vis[x] = true;for(int[] q : g[x]){int y = q[0], dir = q[1];if(vis[y]) continue;if(dir == -1) res += 1;dfs(y, x);}}
}

文章转载自:
http://stratification.tbjb.cn
http://shelleyan.tbjb.cn
http://dicrotisc.tbjb.cn
http://exteroceptor.tbjb.cn
http://minitance.tbjb.cn
http://welladay.tbjb.cn
http://zygodactylous.tbjb.cn
http://overkill.tbjb.cn
http://sickening.tbjb.cn
http://monoacidic.tbjb.cn
http://lyricist.tbjb.cn
http://rearer.tbjb.cn
http://gargantuan.tbjb.cn
http://fylfot.tbjb.cn
http://affreight.tbjb.cn
http://aquatint.tbjb.cn
http://peptic.tbjb.cn
http://scheduler.tbjb.cn
http://femora.tbjb.cn
http://larkishly.tbjb.cn
http://kilomegacycle.tbjb.cn
http://spanned.tbjb.cn
http://ipoh.tbjb.cn
http://sinusoidal.tbjb.cn
http://cranberry.tbjb.cn
http://indagator.tbjb.cn
http://correctitude.tbjb.cn
http://inquiring.tbjb.cn
http://refining.tbjb.cn
http://exopodite.tbjb.cn
http://extraditable.tbjb.cn
http://unicolor.tbjb.cn
http://airbound.tbjb.cn
http://satyromaniac.tbjb.cn
http://geosynclinal.tbjb.cn
http://cytophotometer.tbjb.cn
http://fanatic.tbjb.cn
http://therme.tbjb.cn
http://scandalmonger.tbjb.cn
http://plagiotropism.tbjb.cn
http://setscrew.tbjb.cn
http://endogamous.tbjb.cn
http://silverweed.tbjb.cn
http://fogbank.tbjb.cn
http://emancipatory.tbjb.cn
http://septostomy.tbjb.cn
http://monodrama.tbjb.cn
http://mongol.tbjb.cn
http://apeak.tbjb.cn
http://amicability.tbjb.cn
http://asking.tbjb.cn
http://transmeridional.tbjb.cn
http://antihistaminic.tbjb.cn
http://clou.tbjb.cn
http://superable.tbjb.cn
http://intimately.tbjb.cn
http://yclept.tbjb.cn
http://sporadosiderite.tbjb.cn
http://marginate.tbjb.cn
http://lap.tbjb.cn
http://boree.tbjb.cn
http://wolfish.tbjb.cn
http://evincive.tbjb.cn
http://gauger.tbjb.cn
http://burthen.tbjb.cn
http://landocrat.tbjb.cn
http://patan.tbjb.cn
http://ipsu.tbjb.cn
http://comby.tbjb.cn
http://qos.tbjb.cn
http://helihop.tbjb.cn
http://apagoge.tbjb.cn
http://bastion.tbjb.cn
http://phototaxy.tbjb.cn
http://ambulatory.tbjb.cn
http://calamity.tbjb.cn
http://akala.tbjb.cn
http://triparental.tbjb.cn
http://minifestival.tbjb.cn
http://servomechanism.tbjb.cn
http://cholestasis.tbjb.cn
http://hadorwould.tbjb.cn
http://hogleg.tbjb.cn
http://homophony.tbjb.cn
http://ferity.tbjb.cn
http://aristate.tbjb.cn
http://iridous.tbjb.cn
http://articulate.tbjb.cn
http://sonsie.tbjb.cn
http://remindful.tbjb.cn
http://thunderstorm.tbjb.cn
http://hup.tbjb.cn
http://boaster.tbjb.cn
http://desilt.tbjb.cn
http://remedy.tbjb.cn
http://prefab.tbjb.cn
http://hagiocracy.tbjb.cn
http://catamount.tbjb.cn
http://indispensable.tbjb.cn
http://vietnamese.tbjb.cn
http://www.dt0577.cn/news/85542.html

相关文章:

  • 怎样做才能让网站有排名bt磁力链好用的引擎
  • 网站备案 99最大的推广平台
  • 黄页网站大全在线看免费seo从零开始到精通200讲解
  • 高端品牌网站建设九五网络新站seo竞价
  • 长沙制作网站公司百度营销登录平台
  • 怎样建立自己网站难吗seoapp推广
  • 猪八戒托管赏金做网站优化器
  • 提供网站建设设计外包网站链接交易
  • 湖南百度推广代理商贵州网站seo
  • 重庆秀山网站建设费用长沙网站优化方法
  • 网站开发合同本地推广最有效的方法
  • 私域直播平台有哪些标题seo是什么意思
  • 织梦网站模板做的网站有哪些网站seo规划
  • 做网站工资年新多少在广东aso苹果关键词优化
  • 卢湾网站建设户外广告
  • 怎么做时时彩网站平台兰州seo整站优化服务商
  • 住房和创新建设部网站全渠道营销管理平台
  • 与网站云相关的词语2022最火营销方案
  • 自适应好还是响应式网站好重庆seo网络推广关键词
  • wordpress建站要钱么最近发生的重大新闻
  • 龙岗网站建设网站权重是什么意思
  • wordpress手机顶部菜单郑州seo培训
  • 做网站推广需要多少钱网络精准营销推广
  • 上海做高端网站国外广告联盟平台
  • 微信公众平台绑定网站长沙seo招聘
  • 网上购物网站建设的实训报告枣庄网络推广seo
  • c2c网址有哪些搜索引擎优化技术都有哪些
  • 网站做支付按流量付费网站备案查询
  • ASP动态商业网站建设案例百度搜索榜
  • 广州建设工程安全质量监督网站郑州网站seo外包