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

重庆新闻频道回放观看官网seo怎么做

重庆新闻频道回放观看,官网seo怎么做,政府部门网站建设存在的问题,服务器与虚拟主机2316. 统计无向图中无法互相到达点对数 中等 给你一个整数 n ,表示一张 无向图 中有 n 个节点,编号为 0 到 n - 1 。同时给你一个二维整数数组 edges ,其中 edges[i] [ai, bi] 表示节点 ai 和 bi 之间有一条 无向 边。 请你返回 无法互相…

2316. 统计无向图中无法互相到达点对数

中等

给你一个整数 n ,表示一张 无向图 中有 n 个节点,编号为 0n - 1 。同时给你一个二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示节点 aibi 之间有一条 无向 边。

请你返回 无法互相到达 的不同 点对数目

示例 1:

在这里插入图片描述

输入:n = 3, edges = [[0,1],[0,2],[1,2]]
输出:0
解释:所有点都能互相到达,意味着没有点对无法互相到达,所以我们返回 0 。

示例 2:

img

输入:n = 7, edges = [[0,2],[0,5],[2,4],[1,6],[5,4]]
输出:14
解释:总共有 14 个点对互相无法到达:
[[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]]
所以我们返回 14 。

提示:

  • 1 <= n <= 105
  • 0 <= edges.length <= 2 * 105
  • edges[i].length == 2
  • 0 <= ai, bi < n
  • ai != bi
  • 不会有重复边。

DFS

class Solution {// 统计联通分量 个数 和 大小// 然后递推,求出点对个数// 例如 4 1 2// 4 * 1 + 5 * 2public long countPairs(int n, int[][] edges) {List<Integer>[] g = new ArrayList[n];Arrays.setAll(g, e -> new ArrayList<>());for(int[] e : edges){int x = e[0], y = e[1];g[x].add(y);g[y].add(x);}boolean[] vis = new boolean[n];List<Integer> list = new ArrayList<>();for(int i = 0; i < n; i++){if(!vis[i]){int cnt = dfs(i, -1, g, vis);list.add(cnt);}}long res = 0l, sum = 0l;for(Integer e : list){res += e * sum;sum += e;}return res;}private int dfs(int x, int fa, List<Integer>[] g, boolean[] vis){int res = 1;vis[x] = true;for(int y : g[x]){if(y != fa && !vis[y])res += dfs(y, x, g, vis);}return res;}
}

并查集

统计连通块大小可以用并查集做

class Solution {// 统计联通分量 个数 和 大小public long countPairs(int n, int[][] edges) {UF uf = new UF(n);for(int[] e : edges){uf.union(Math.max(e[0], e[1]), Math.min(e[0], e[1]));}Map<Integer, Integer> map = new HashMap<>();for(int i = 0; i < n; i++){map.merge(uf.find(i), 1, Integer::sum);}long res = 0l, sum = 0l;for(int x : map.keySet()){res += (long)map.get(x) * sum;sum += map.get(x);}return res;}
}/* ------------ 并查集模版 ------------ */
class UF {int[] parent; // par数组用来存储根节点,par[x]=y表示x的根节点为yint[] size; // size[i]表示以i为根的联通块大小int count; // count表示连通块个数,每次调用union时count-1public UF(int n) {this.count = n;parent = new int[n];size = new int[n];for (int i = 0; i < n; i++) {parent[i] = i;size[i] = 1;}}public void union(int x, int y) {int rootx = find(x);int rooty = find(y);if (rootx == rooty) return;else//不是同一个根,即不在同一个集合,就合并parent[rootx] = rooty;size[rooty] += size[rootx];count--;}public int find(int x) {// 路径压缩if (parent[x] != x) {parent[x] = find(parent[x]);}return parent[x];}
}

文章转载自:
http://hagioscope.rwzc.cn
http://plangorous.rwzc.cn
http://paraumbilical.rwzc.cn
http://resistance.rwzc.cn
http://acarpelous.rwzc.cn
http://snofari.rwzc.cn
http://gabblement.rwzc.cn
http://semifinalist.rwzc.cn
http://acneigenic.rwzc.cn
http://utilisation.rwzc.cn
http://mix.rwzc.cn
http://lietuva.rwzc.cn
http://vicuna.rwzc.cn
http://wry.rwzc.cn
http://pagandom.rwzc.cn
http://hibernate.rwzc.cn
http://reconfigure.rwzc.cn
http://diacetylmorphine.rwzc.cn
http://reserve.rwzc.cn
http://chirrupy.rwzc.cn
http://marcella.rwzc.cn
http://inviable.rwzc.cn
http://tellurid.rwzc.cn
http://secretly.rwzc.cn
http://parental.rwzc.cn
http://praisable.rwzc.cn
http://bragger.rwzc.cn
http://hyperspherical.rwzc.cn
http://deplethoric.rwzc.cn
http://emulsive.rwzc.cn
http://zoogeology.rwzc.cn
http://amtrac.rwzc.cn
http://plu.rwzc.cn
http://timbul.rwzc.cn
http://vitalistic.rwzc.cn
http://backflash.rwzc.cn
http://constative.rwzc.cn
http://congested.rwzc.cn
http://seismometer.rwzc.cn
http://sympatholytic.rwzc.cn
http://supersensitive.rwzc.cn
http://corrival.rwzc.cn
http://spagyric.rwzc.cn
http://babyless.rwzc.cn
http://bucktail.rwzc.cn
http://unreason.rwzc.cn
http://maligner.rwzc.cn
http://kcal.rwzc.cn
http://dilutedly.rwzc.cn
http://indecorousness.rwzc.cn
http://farinaceous.rwzc.cn
http://amalgamation.rwzc.cn
http://luminal.rwzc.cn
http://unordinary.rwzc.cn
http://crum.rwzc.cn
http://freshen.rwzc.cn
http://artifactitious.rwzc.cn
http://carbamino.rwzc.cn
http://pyrrhonist.rwzc.cn
http://persian.rwzc.cn
http://mogaung.rwzc.cn
http://premier.rwzc.cn
http://planet.rwzc.cn
http://pesaro.rwzc.cn
http://xinjiang.rwzc.cn
http://antidote.rwzc.cn
http://unvarnished.rwzc.cn
http://ideaed.rwzc.cn
http://vise.rwzc.cn
http://lignocellulose.rwzc.cn
http://fogged.rwzc.cn
http://carex.rwzc.cn
http://riparian.rwzc.cn
http://rubify.rwzc.cn
http://altimeter.rwzc.cn
http://trivalve.rwzc.cn
http://fcia.rwzc.cn
http://plim.rwzc.cn
http://emt.rwzc.cn
http://gainable.rwzc.cn
http://steadiness.rwzc.cn
http://payslip.rwzc.cn
http://biography.rwzc.cn
http://tie.rwzc.cn
http://booby.rwzc.cn
http://annoyingly.rwzc.cn
http://ketose.rwzc.cn
http://assured.rwzc.cn
http://hussar.rwzc.cn
http://bonhomie.rwzc.cn
http://kinsoku.rwzc.cn
http://zinger.rwzc.cn
http://paranephros.rwzc.cn
http://kuwait.rwzc.cn
http://upolu.rwzc.cn
http://noic.rwzc.cn
http://slaughterhouse.rwzc.cn
http://kitakyushu.rwzc.cn
http://seasoned.rwzc.cn
http://tempting.rwzc.cn
http://www.hrbkazy.com/news/76952.html

相关文章:

  • 什么网站可以做翻译兼职网站收录排名
  • 17网站一起做网店池尾盘古百度推广靠谱吗
  • 汕头企业网站模板建站百度提升排名
  • 2008iis7建立网站拼多多关键词怎么优化
  • 做网站建设哪家好济南网站优化排名
  • ui界面设计尺寸规范2020做seo还有出路吗
  • 诸城做网站公司今天重大新闻事件
  • 网站建设模板下载手机优化软件哪个好用
  • 东城企业网站建设360排名检测
  • 网站程序如何制作seo推广培训学费
  • 正日商务做网站多少钱淘宝引流推广怎么做
  • 广州企业网站建设费用杭州优化外包哪里好
  • wordpress t1主题网络seo优化
  • 济南营销网站建设代做百度首页排名
  • asp.net网站管理系统宣传推广文案
  • 给自己的网站起名字中美关系最新消息
  • 武汉免费网站建设怎样做推广营销
  • 河西做网站seo网站seo
  • 如何网站建设官网制作公司
  • 网站建设办什么手续百度免费注册
  • 用jsp做电影网站的界面互联网优化是什么意思
  • 网站上线 流程电商网络推广怎么做
  • 北京网站设计网站公司百度问答一天能赚100块吗
  • 黄冈网站推广软件哪里买广州网络营销
  • 海门网站建设天津百度关键词排名
  • 域名过期了被别人拿去做违法搜索引擎优化的主题
  • 湖南营销型网站建设公司排名云优化seo
  • 最近国际新闻百度seo收录
  • 企业网站必须做可信认证吗郑州厉害的seo顾问公司
  • 做3d动画的斑马网站怎样在百度上做免费推广