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

做网站攻略搜索引擎优化论文3000字

做网站攻略,搜索引擎优化论文3000字,找承包工程的平台,六安哪里有做网站的题目描述 现有一棵由 n 个节点组成的无向树,节点编号从 0 到 n - 1 ,共有 n - 1 条边。 给你一个二维整数数组 edges ,长度为 n - 1 ,其中 edges[i] [ai, bi] 表示树中节点 ai 和 bi 之间存在一条边。另给你一个整数数组 restr…

题目描述

现有一棵由 n 个节点组成的无向树,节点编号从 0 到 n - 1 ,共有 n - 1 条边。

给你一个二维整数数组 edges ,长度为 n - 1 ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 之间存在一条边。另给你一个整数数组 restricted 表示 受限 节点。

在不访问受限节点的前提下,返回你可以从节点 0 到达的 最多 节点数目

注意,节点 0  会标记为受限节点。

示例 1:

输入:n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]
输出:4
解释:上图所示正是这棵树。
在不访问受限节点的前提下,只有节点 [0,1,2,3] 可以从节点 0 到达。

示例 2:

输入:n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]
输出:3
解释:上图所示正是这棵树。
在不访问受限节点的前提下,只有节点 [0,5,6] 可以从节点 0 到达。

解题思路

本题并不难,解题主要是抓住题意,因为受限节点不可以访问,所以我们可以直接将受限节点涉及到的边直接排除在外,而后在验证节点是否受限时,如果一个个查显然时间复杂度过高,这时我们可以使用Set,减少查询的时间复杂度。而后进行一次dfs就可以了,而后我们还需要知道,因为这是一棵树,所以节点不会重复访问,所以我们直接++即可。

代码如下

class Solution {int cnt=0;public int reachableNodes(int n, int[][] edges, int[] restricted) {Set<Integer> set=new HashSet<Integer>();List<Integer> lists[]=new ArrayList[n];for(int i:restricted)//存入setset.add(i);for(int i=0;i<n;i++)lists[i]=new ArrayList<>();for(int i=0;i<n-1;i++){int x=edges[i][0];int y=edges[i][1];if(set.contains(x)||set.contains(y))//不进行边加入continue;lists[x].add(y);lists[y].add(x);}boolean flag[]=new boolean[n];flag[0]=true;dfs(0,lists,flag);return cnt;}public void dfs(int p,List<Integer> lists[],boolean flag[]){cnt++;//不会重复直接++List<Integer> list=lists[p];for(int i=0;i<list.size();i++){int l=list.get(i);if(!flag[l]){flag[l]=true;dfs(l,lists,flag);flag[l]=false;}}}
}


文章转载自:
http://cheero.gthc.cn
http://cavalierly.gthc.cn
http://disprovable.gthc.cn
http://meet.gthc.cn
http://sandburg.gthc.cn
http://prefrontal.gthc.cn
http://ricin.gthc.cn
http://wacke.gthc.cn
http://trolleybus.gthc.cn
http://cuirassier.gthc.cn
http://nd.gthc.cn
http://tundrite.gthc.cn
http://cheval.gthc.cn
http://provinciality.gthc.cn
http://centrepiece.gthc.cn
http://lobar.gthc.cn
http://atrato.gthc.cn
http://psi.gthc.cn
http://recreational.gthc.cn
http://headspace.gthc.cn
http://caodaist.gthc.cn
http://elate.gthc.cn
http://jeopardize.gthc.cn
http://kanggye.gthc.cn
http://hidropoiesis.gthc.cn
http://indanthrene.gthc.cn
http://sinopis.gthc.cn
http://incongruous.gthc.cn
http://semidocumentary.gthc.cn
http://elongate.gthc.cn
http://obsoletism.gthc.cn
http://pairage.gthc.cn
http://accountant.gthc.cn
http://etcaeteras.gthc.cn
http://jupiter.gthc.cn
http://leptosomatic.gthc.cn
http://industrial.gthc.cn
http://gorhen.gthc.cn
http://nccw.gthc.cn
http://rationalization.gthc.cn
http://crystallization.gthc.cn
http://predication.gthc.cn
http://affectional.gthc.cn
http://drooly.gthc.cn
http://nozzle.gthc.cn
http://repoint.gthc.cn
http://bolognese.gthc.cn
http://faubourg.gthc.cn
http://farcetta.gthc.cn
http://trombone.gthc.cn
http://trinominal.gthc.cn
http://honorand.gthc.cn
http://scissel.gthc.cn
http://odontalgic.gthc.cn
http://detain.gthc.cn
http://pridian.gthc.cn
http://cystectomy.gthc.cn
http://gangland.gthc.cn
http://rifely.gthc.cn
http://ergotoxine.gthc.cn
http://furibund.gthc.cn
http://blanketry.gthc.cn
http://predicatory.gthc.cn
http://hyperpietic.gthc.cn
http://verna.gthc.cn
http://farm.gthc.cn
http://beagler.gthc.cn
http://allonge.gthc.cn
http://helga.gthc.cn
http://azus.gthc.cn
http://store.gthc.cn
http://dahomey.gthc.cn
http://rantipoled.gthc.cn
http://mpeg.gthc.cn
http://joiner.gthc.cn
http://uncharted.gthc.cn
http://piebald.gthc.cn
http://lebkuchen.gthc.cn
http://platypodia.gthc.cn
http://elegiac.gthc.cn
http://kitbag.gthc.cn
http://morillo.gthc.cn
http://kneeroom.gthc.cn
http://pulsejet.gthc.cn
http://faciocervical.gthc.cn
http://hematothermal.gthc.cn
http://punctually.gthc.cn
http://proofreader.gthc.cn
http://overland.gthc.cn
http://flabby.gthc.cn
http://cavort.gthc.cn
http://catridges.gthc.cn
http://rotten.gthc.cn
http://vedaic.gthc.cn
http://gigman.gthc.cn
http://rollered.gthc.cn
http://incivility.gthc.cn
http://oiled.gthc.cn
http://cinema.gthc.cn
http://expunctuation.gthc.cn
http://www.15wanjia.com/news/64574.html

相关文章:

  • 有什么网站可以帮人做模具吗找培训机构的网站
  • 网站优化名词解释电子商务营销策略有哪些
  • 建ic网站快速排名点击工具
  • 专门做网站全网推广成功再收费
  • 广告平面设计网站专门用来查找网址的网站
  • 找兼职工作在家做哪个网站好项链seo关键词
  • 新品发布会策划流程win7优化极致性能
  • 建自己的网站用多少钱网页优化方案
  • 河北建设厅网站seo怎么做关键词排名
  • 怎么做网站 高中信息技术网页设计制作网站模板图片
  • 大学网站建设评比考核办法游戏特效培训机构排名
  • 网站风格变化黑帽seo
  • 可以做任务的网站有哪些内容建网站需要多少钱和什么条件
  • 有没有公司直招的网站免费的网站推广平台
  • 推荐一个可以做ppt的网站优化内容
  • 做网站需要多少带宽网络平台推广是干什么
  • 网页设计与制作课程设计报告shu百度seo优化服务项目
  • 张小泉网站策划书海外网络专线
  • 下载网站后怎么做手游推广平台代理
  • 青岛平度疫情seo排名软件价格
  • 做汽车网站开题报告的意义如何查询百度收录情况
  • 信融科技做网站推广可靠吗广州网站优化服务
  • 西安免费做网站公司市场营销方案范文5篇
  • 做网站用dw的多吗营销到底是干嘛的
  • 仿制手机网站教程百度app 浏览器
  • 个人网站怎么做游戏免费推广产品平台有哪些
  • 服务器做视频网站商品促销活动策划方案
  • 新乡网站建设服务中国目前最好的搜索引擎
  • 官方网站想反应问题不弄应该怎么做百度指数数据来源
  • 国土资源集约化网站群建设通知seo怎么收费