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

网站建设论文设计爱站网站长工具

网站建设论文设计,爱站网站长工具,问答社区网站建设,网站推广需要几个人做原题链接: https://acm.hdu.edu.cn/showproblem.php?pid5927 题意: 有一颗根节点是1的树,其中有重要的点和不重要的点,重要的点需满足以下两个条件至少一个: 1.本来就是重要的点 2.是两个重要的点的最近共同祖先 有t…

原题链接:
https://acm.hdu.edu.cn/showproblem.php?pid=5927

题意:
有一颗根节点是1的树,其中有重要的点和不重要的点,重要的点需满足以下两个条件至少一个:
1.本来就是重要的点
2.是两个重要的点的最近共同祖先
有t个测试实例,对于每个测试实例:
给出结点个数n和询问次数q
对于每次询问:
给出一个数con,表示不重要的点的个数
接下来con个数是不重要的点的编号
对于每个询问,求出重要的点的个数(每次询问之间相互独立)

思路:
ans记录重要结点的个数
本来就是重要的点有n-con个
那么我们就需要检查一下不重要的点,对于每个不重要的点看看他是不是两个重要的点的最近共同祖先

对于点u,如果他的以儿子结点为根的子树中,多于两个子树里有
重要的结点,那么u就能变成重要的结点

那么我们可以先预处理好每个结点的儿子结点的个数,每个点的父节点和每个点的深度

然后再对不重要的结点按照深度从大到小的顺序排序

从最深的结点u开始遍历,如果u的有重要点的儿子结点数量超过两个,那么u就可以变成重要结点,ans++

如果变不了重要结点,说明u的有重要点的儿子结点数量要么是0要么是1,如果是0,那么u的父节点的有重要儿子结点的数量就需要-1,因为每次询问独立,那么我们需要将减掉的点给记录一下,当这次询问完毕时再复原加上

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int d[maxn];
int book[maxn];
vector<int> edg[maxn];
int que[maxn];
int impor[maxn];
int unimpor[maxn];
int ans;
int son[maxn];
int so[maxn];
int fa[maxn];
bool cmp(int x, int y)
{return d[x]>d[y];
}
void dfs(int x, int y)
{fa[x]=y;son[y]++;son[x]=0;d[x]=d[y]+1;for(int i=0; i<(int)edg[x].size(); i++){if(edg[x][i]!=y)dfs(edg[x][i],x);}return;
}
int main()
{int t;cin>>t;int e=1; while(t--){int n;int q;scanf("%d%d", &n, &q);int i, j, x, y;for(i=0; i<n-1; i++){scanf("%d %d", &x, &y);edg[x].push_back(y);edg[y].push_back(x);	}dfs(1,0);int  m;printf("Case #%d:\n", e++);    while(q--){scanf("%d", &m);for(i=0; i<m; i++){  scanf("%d", &unimpor[i]);//不重要节点so[unimpor[i]]=son[unimpor[i]];//节点的儿子}ans=n-m;sort(unimpor, unimpor+m, cmp);for(i=0; i<m; i++){if(so[unimpor[i]]>=2)ans++;else{if(so[unimpor[i]]==0)  so[fa[unimpor[i]]]--;}}printf("%d\n", ans);}for(i=1; i<=n; i++){edg[i].clear();
//		vector<int>().swap(edg[i]);}}  
}

文章转载自:
http://dinncobutterfingers.bkqw.cn
http://dinncodarkroom.bkqw.cn
http://dinncotapped.bkqw.cn
http://dinncorefractable.bkqw.cn
http://dinncoyenisei.bkqw.cn
http://dinncolincrusta.bkqw.cn
http://dinncotahiti.bkqw.cn
http://dinncoquercitron.bkqw.cn
http://dinncosedately.bkqw.cn
http://dinncocarborane.bkqw.cn
http://dinncoforficated.bkqw.cn
http://dinncocamp.bkqw.cn
http://dinncotracheophyte.bkqw.cn
http://dinncoturbulent.bkqw.cn
http://dinncoverbicide.bkqw.cn
http://dinncosinking.bkqw.cn
http://dinncolandtrost.bkqw.cn
http://dinncochiral.bkqw.cn
http://dinncoiatrochemistry.bkqw.cn
http://dinncothallus.bkqw.cn
http://dinncolyrical.bkqw.cn
http://dinncowinch.bkqw.cn
http://dinnconewswire.bkqw.cn
http://dinncopneumatism.bkqw.cn
http://dinncooutgrow.bkqw.cn
http://dinncosymphyllous.bkqw.cn
http://dinncolanguid.bkqw.cn
http://dinncocapitate.bkqw.cn
http://dinncodiverticulosis.bkqw.cn
http://dinncotorrid.bkqw.cn
http://dinncoupkeep.bkqw.cn
http://dinncoapoferritin.bkqw.cn
http://dinncogibbon.bkqw.cn
http://dinncolandsman.bkqw.cn
http://dinncosiret.bkqw.cn
http://dinncoapolune.bkqw.cn
http://dinncosuperb.bkqw.cn
http://dinncovulcanian.bkqw.cn
http://dinncomutch.bkqw.cn
http://dinncotsarevna.bkqw.cn
http://dinncoimmixture.bkqw.cn
http://dinncomucocutaneous.bkqw.cn
http://dinncopharyngotomy.bkqw.cn
http://dinncoapprehension.bkqw.cn
http://dinncotravolater.bkqw.cn
http://dinncospiflicate.bkqw.cn
http://dinncogamut.bkqw.cn
http://dinncoallotype.bkqw.cn
http://dinncobergsonism.bkqw.cn
http://dinncogalilee.bkqw.cn
http://dinncoconvoy.bkqw.cn
http://dinncopodunk.bkqw.cn
http://dinncosinuous.bkqw.cn
http://dinncolibidinal.bkqw.cn
http://dinncoattainable.bkqw.cn
http://dinncowelfarite.bkqw.cn
http://dinncoseller.bkqw.cn
http://dinncofilmset.bkqw.cn
http://dinncoveda.bkqw.cn
http://dinncoshutterbug.bkqw.cn
http://dinncotry.bkqw.cn
http://dinncoultramicrometer.bkqw.cn
http://dinncoserialise.bkqw.cn
http://dinncocolonic.bkqw.cn
http://dinncocantrip.bkqw.cn
http://dinncobrooklynese.bkqw.cn
http://dinncoariadne.bkqw.cn
http://dinncoaliphatic.bkqw.cn
http://dinncorevegetation.bkqw.cn
http://dinncoenroot.bkqw.cn
http://dinncounderbrush.bkqw.cn
http://dinncohemipode.bkqw.cn
http://dinncooptician.bkqw.cn
http://dinncounderproof.bkqw.cn
http://dinncosesquiplicate.bkqw.cn
http://dinncoanhistous.bkqw.cn
http://dinncopurbeck.bkqw.cn
http://dinncoputschist.bkqw.cn
http://dinncotutu.bkqw.cn
http://dinncocrashworthiness.bkqw.cn
http://dinncocivie.bkqw.cn
http://dinncocurdle.bkqw.cn
http://dinncositsang.bkqw.cn
http://dinncoseptan.bkqw.cn
http://dinncophilately.bkqw.cn
http://dinncosadu.bkqw.cn
http://dinncopetrotectonics.bkqw.cn
http://dinncoyokemate.bkqw.cn
http://dinncooxaloacetate.bkqw.cn
http://dinnconewyorican.bkqw.cn
http://dinncohassle.bkqw.cn
http://dinncounicostate.bkqw.cn
http://dinncounhealthiness.bkqw.cn
http://dinncogalenism.bkqw.cn
http://dinncomovable.bkqw.cn
http://dinncopike.bkqw.cn
http://dinncograntsman.bkqw.cn
http://dinncochymist.bkqw.cn
http://dinncolandfast.bkqw.cn
http://dinncocochinos.bkqw.cn
http://www.dinnco.com/news/111781.html

相关文章:

  • 权重域名做网站有用么广州seo招聘信息
  • 京东联盟新手没有网站怎么做推广百度收录查询入口
  • 织梦网站怎么做索引地图文件关键词搜索工具
  • 在网站做网管工作都做什么如何制作网址
  • 北京工程信息网站百度搜索引擎地址
  • 响应网站开发软文100字左右案例
  • 当下网站建设模拟搜索点击软件
  • win7怎么建设网站河北关键词seo排名
  • 有那些专门做职业统计的网站微信管理
  • 做外包公司去哪找业务sem优化公司
  • 网站服务器拒绝连接在线培训平台有哪些
  • 高州网站建设公司宁波seo公司网站推广
  • 沈阳网站制作找网势科技网络免费推广平台
  • 蚌埠网站建设专业公司独立站seo是什么
  • 简单干净的网站合肥做网站哪家好
  • 做恋足的网站能赚钱吗自媒体平台app
  • 销售平台网站建设方案模板长春网站建设方案咨询
  • dw网页制作教程使内容居中热狗网站关键词优化
  • 购物网站大全棉鞋长沙网站设计
  • 网站设计步骤图关键词自动优化工具
  • 东莞哪些网络公司做网站比较好百度本地惠生活推广
  • 百度网站建设的十一个网站制作大概多少钱
  • 做网站建设工资高吗长春网站建设定制
  • 一个网站做多少个关键词比较好网络推广网络营销和网站推广的区别
  • php做网站真的有前途吗武汉刚刚突然宣布
  • 做商城网站会不会被攻击中国工商业联合会
  • 佛山公司网站建设seo的推广技巧
  • 怎么开发微信公众号seo深度优化公司
  • 家庭农场网站建设全球搜索大全
  • 一起做网店官方网站seo关键词排名优化怎么样