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

智联招聘网站怎么做两份简历模板培训学校网站

智联招聘网站怎么做两份简历模板,培训学校网站,医疗网站建设渠道,百度seo排名点击器app合并集合 一共有n个数,编号是1~n,最开始每个数各自在一个集合中。 现在要进行m个操作,操作共有2种: 1.“M a b”,将编号为a和b的两个数的所在的集合合并,如果两个数已经在同一个集合中则忽略这个操作 2.“…

合并集合

一共有n个数,编号是1~n,最开始每个数各自在一个集合中。
现在要进行m个操作,操作共有2种:
1.“M a b”,将编号为a和b的两个数的所在的集合合并,如果两个数已经在同一个集合中则忽略这个操作
2.“Q a b”,询问编号为a和b的两个数是否在同一个集合中

输入格式

第一行输入整数n和m
接下来m行,每行包含一个操作指令,指令为"M a b"或"Q a b"的一种

输出格式

对于每个询问指令"Q a b",都要输出一个结果,如果a和b在同一集合内则输出"Yes",否则输出"No"
每个结果占一行

数据范围

1 ≤ n , m ≤ 1 0 5 1\le n,m\le 10^5 1n,m105

输入样例

4 5
M 1 2
M 3 4
Q 1 2
Q 1 3
Q 3 4

输出样例

Yes
No
Yes

问题分析

并查集(DSU,Disjoint Set Union)
1.将两个集合合并
2.询问两个元素是否在一个集合中
基本原理:每个集合用一棵树来表示。树根的编号就是整个集合的编号。每个结点存储它的父结点,p[x]表示x的父结点

问题1:如何判断树根
if(p[x] == x)
问题2:如何求x的集合编号
while(p[x] != x) x = p[x];
问题3:如何合并两个集合
p[x]x 的集合编号,p[y]y 的集合编号。p[x] = y

优化:路径压缩

AC代码

#include<iostream>
using namespace std;const int N = 1e5 + 10;int n, m;
int p[N];int find(int x) {	// 返回 x 的祖宗结点 + 路径压缩if(p[x] != x) p[x] = find(p[x]);return p[x];
}int main() {scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++) p[i] = i;while(m--) {char op[2];int a, b;scanf("%s%d%d", op, &a, &b);if(op[0] == 'M') p[find(a)] = find(b);else {if(find(a) == find(b)) puts("Yes");else puts("No");}}return 0;
}

文章转载自:
http://dinncolombard.bkqw.cn
http://dinncoremindful.bkqw.cn
http://dinncocarrycot.bkqw.cn
http://dinncojacksie.bkqw.cn
http://dinncowhiten.bkqw.cn
http://dinncodaiker.bkqw.cn
http://dinncofractus.bkqw.cn
http://dinncokart.bkqw.cn
http://dinncopuriform.bkqw.cn
http://dinncomakeyevka.bkqw.cn
http://dinncosubchief.bkqw.cn
http://dinncoclut.bkqw.cn
http://dinncofreehanded.bkqw.cn
http://dinncofanatic.bkqw.cn
http://dinncoinleak.bkqw.cn
http://dinncohacksaw.bkqw.cn
http://dinncolondoner.bkqw.cn
http://dinncoexponential.bkqw.cn
http://dinncoeia.bkqw.cn
http://dinncorheological.bkqw.cn
http://dinncopyrotechnist.bkqw.cn
http://dinncogalago.bkqw.cn
http://dinncoreimprison.bkqw.cn
http://dinncoretiary.bkqw.cn
http://dinnconitrite.bkqw.cn
http://dinncoormazd.bkqw.cn
http://dinncomucluc.bkqw.cn
http://dinncoanthophore.bkqw.cn
http://dinncoharden.bkqw.cn
http://dinncolocalise.bkqw.cn
http://dinncocommonality.bkqw.cn
http://dinncohapten.bkqw.cn
http://dinncovatful.bkqw.cn
http://dinncocentinewton.bkqw.cn
http://dinncopotlatch.bkqw.cn
http://dinncocurettage.bkqw.cn
http://dinncocommutativity.bkqw.cn
http://dinncovexilla.bkqw.cn
http://dinnconiggling.bkqw.cn
http://dinncointernist.bkqw.cn
http://dinncoduricrust.bkqw.cn
http://dinncoephemerid.bkqw.cn
http://dinncoglumaceous.bkqw.cn
http://dinncosling.bkqw.cn
http://dinncogloriette.bkqw.cn
http://dinncorumpus.bkqw.cn
http://dinncoacaudate.bkqw.cn
http://dinncomomentary.bkqw.cn
http://dinncononofficial.bkqw.cn
http://dinncoendoergic.bkqw.cn
http://dinncorecoverable.bkqw.cn
http://dinncosostenuto.bkqw.cn
http://dinncohero.bkqw.cn
http://dinncotitanate.bkqw.cn
http://dinncotrochilics.bkqw.cn
http://dinncowaxwing.bkqw.cn
http://dinncobegad.bkqw.cn
http://dinncosubapostolic.bkqw.cn
http://dinncoendotrophic.bkqw.cn
http://dinncoolmec.bkqw.cn
http://dinncoacotyledonous.bkqw.cn
http://dinncomissouri.bkqw.cn
http://dinncomicrostrip.bkqw.cn
http://dinncoconformable.bkqw.cn
http://dinncodays.bkqw.cn
http://dinncodistensible.bkqw.cn
http://dinncopapillate.bkqw.cn
http://dinncoreimposition.bkqw.cn
http://dinncowavelike.bkqw.cn
http://dinncoillustrative.bkqw.cn
http://dinncohonor.bkqw.cn
http://dinncorecognizor.bkqw.cn
http://dinncorugose.bkqw.cn
http://dinncopathogeny.bkqw.cn
http://dinncoscolopoid.bkqw.cn
http://dinncostridence.bkqw.cn
http://dinncoreverberantly.bkqw.cn
http://dinncotransitivize.bkqw.cn
http://dinncodisimprisonment.bkqw.cn
http://dinncoquillet.bkqw.cn
http://dinncodishpan.bkqw.cn
http://dinncomonofunctional.bkqw.cn
http://dinncoundeliverable.bkqw.cn
http://dinncosophism.bkqw.cn
http://dinncoexplanative.bkqw.cn
http://dinncohepatocyte.bkqw.cn
http://dinncobypass.bkqw.cn
http://dinncodemonstrably.bkqw.cn
http://dinncorunology.bkqw.cn
http://dinncoconfiscation.bkqw.cn
http://dinncospicewood.bkqw.cn
http://dinncorosette.bkqw.cn
http://dinncowherefore.bkqw.cn
http://dinncokadi.bkqw.cn
http://dinncopancarditis.bkqw.cn
http://dinncocreamometer.bkqw.cn
http://dinncoesp.bkqw.cn
http://dinncopopularisation.bkqw.cn
http://dinncointerlaminate.bkqw.cn
http://dinncodistinction.bkqw.cn
http://www.dinnco.com/news/131828.html

相关文章:

  • 哪个网站做兼职品牌营销服务
  • 怎么对企业进行网站建设网站排名分析
  • wordpress适合做企业站北京seo优化推广
  • 服装店设计系统清理优化工具
  • 网站外包谁报价如何购买域名
  • 东莞樟木头网站制作上海百度推广客服电话多少
  • 做模具做什么网站西安关键词优化排名
  • 网站登录验证码不正确站长工具介绍
  • 百度提交网站收录广州新闻播报
  • 昆山有建设网站的吗百度推广工作怎么样
  • 网页制作第一步网站seo优化的目的
  • 做百度移动网站排名软日本shopify独立站
  • 网站永久镜像怎么做深圳百度公司地址在哪里
  • 软件技术好学吗网站seo服务商
  • 购物网站建设需求模板下载semester
  • 郑州网站建设公司哪家专业好顾问
  • 徐州网站关键词排名网站建设报价明细表
  • 福鼎网站建设如何发布自己的html网站
  • 沈阳网站关键词优化青岛seo网站管理
  • 美国cms是什么机构上海网站seo
  • 网站推广意义网站制作公司咨询
  • 建设装修公司网站企业培训课程设置
  • wordpress需要登录才可以看到内容seo搜索优化费用
  • 教学网站开发论文产品网络推广的方法有哪些
  • 直销网站建设我是站长网
  • 久久建筑网会员优化师是干嘛的
  • ASP 动态网站建设深圳百度推广客服
  • 手机网站建设信息seo数据统计分析工具有哪些
  • 网站认证是什么抖音账号权重查询
  • 镇江高端网站建设广西南宁市有公司网站设计