好朋友【并查集】

好朋友 并查集问题 规定: 互反性:A和B是好朋友,等价于B和A是好朋友; 传递性:A和B是好朋友,B和C是好朋友,则A和C也是好朋友; 每组中任意两个都得是好朋友,每两组中不存在好朋友。 这题明显就是求并查集问题,如果是好朋友,那么他们的根节点相同,因此可以对每次输入的数字进行合并判断,若根节点不同则不在一组,如果根节点相同就在一组,因此根节点的数量就是输出的组数。 输入: 7 5 1 2 2 3 3 1 1 4 5 6 代码如下: #include<stdio.h> const int maxn = 11 阅读详情

一、问题描述

        有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定:
        第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友
        第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友,现在给出这些数码宝贝中所有好朋友的信息,问:可以把这些数码宝贝分成多少组,满足每组中的任意两个数码宝贝都是好朋友,而且任意两组之间的数码宝贝都不是好朋友

输入格式

        输入的第一行给右两个正整数n(n<=100)和m(m<=100),分别表示数码宝贝的个数和好朋友的组数,其中数码宝贝编号为1~n。
       接下来有m行,每行两个正整数a和b,表示数码宝贝a和数码宝贝b是好朋友。

输出格式

        输出一个整数,表示这些数码宝贝可以分成的组数

样例输入1

4 2
1 4
2 3

样例输出1

2

样例输入1

7 5
1 2
2 3
3 1
1 4
5 6

样例输出1

3

二、算法实现

1、用一个全局数组,来标记每个元素是不是老祖宗(根)。

2、用一个数组,下标表示元素,数组单元存的内容表示对应元素(下标)的father。

#include<cstdio>
const int maxn=110;

int father[maxn];  //全局变量 
bool isRoot[maxn];  //全局 

int findFather(int x)   //寻祖 
{
	int a=x;
	while(x!=father[x])
	{
		x=father[x];
	}
	while(a!=father[a])
	{
		int z=a;
		a=father[a];
		father[z]=x;
	}
	return x;
}

void Union(int a,int b)   //合并 
{
	int faA=findFather(a);
	int faB=findFather(b);
	if(faA!=faB)
	{
		father[faA]=faB;
	}
}

void init(int n)   //初始化 
{
	for(int i=1;i<=n;i++)
	{
		father[i]=i;
		isRoot[i]=false; 
	}	
}

int main()
{
	int n,m,a,b;
	scanf("%d%d",&n,&m);
	init(n);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		Union(a,b);  //边读入,边合并! 
	}
	for(int i=1;i<=m;i++)
	{
		isRoot[findFather(i)]=true;  //多次重写没事!写起来简单! 
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=isRoot[i];
	}
	printf("%d\n",ans);
	return 0;
}

 

 

 

 

算法学习034 C++好朋友 并查集算法实现 中小学算法思维学习 比赛算法题解 信奥算法解析 C++好朋友 一、题目要求 1、编程实现 小学校园里面有许多的小朋友在上学,其中有些是好朋友,而现在有这么一个规定: 1、小朋友A和小朋友B是好朋友也就意味着小朋友B和小朋友A是好朋友 2、如果小朋友A和小朋友C是好朋友,同时小朋友B和小朋友C也是好朋友,那么A和B也是好朋友 现在给出一些小朋友中所有好朋友之间的信息,问:可以把这些小朋友们分成多少组,满足每组中的任意两个小朋友都是好朋友,且任意两组之间的小朋友都不是好朋友 阅读详情

相关推荐

【深度学习】基于BERT模型的情感分析(附实战完整代码+数据集)

情感分类是一个快速发展的研究领域,尽管众多模型和数据集在二分类任务中显示出很高的准确性,但细粒度的情感分类任务仍然是一个很大改进空间的领域。分析SST-5数据集,Munikar等人的先前工作表明,嵌入工具BERT允许使用简单的模型来实现最新的准确性。

aaaa_hsjsueu的博客 2万+

好朋友(并查集)

1. 问题描述: 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友,现在给出这些数码宝贝中所有好朋友的信息,问:可以把这些数码宝...

二哈 896

ENVI SARscape安装全攻略:从下载到汉化一步到位(附最新试用申请链接)

本文提供ENVI SARscape从下载安装到汉化的完整指南,特别针对InSAR(合成孔径雷达干涉测量)分析环境搭建。详细介绍了系统要求、分步安装流程、汉化优化方法及硬件加速配置,并分享数据处理验证和常见问题解决方案,帮助用户高效搭建遥感数据分析平台。

rnn9storyteller的博客 1414

pat并查集

pat并查集并查集分析难度P1107P1114P1118小结 并查集 1107. Social Clusters (30)-PAT甲级真题 1114. Family Property (25)-PAT甲级真题 1118. Birds in Forest (25)-PAT甲级真题 分析 难度 这三道题难度次序: 1114 > 1107 > 1118 P1107 题目大意: 假设有N个人,每人有k个爱好。 如果两个人有任意一个爱好相同, 那么我们就称这两个人处于一个社交网络中。 问: 这样

qq_43543296的博客 302

(HAL)stm32f407+freertos通过usb驱动移远4G模块-EC600U

文章记录了stm32cubemx+stm32f407+freertos+usb host实现移远4G模块EC600U的usb驱动的调试过程,usb host cdc库的使用和遇到的问题及解决办法。

gongrulin的博客 3900

基于TL431与光耦的电压反馈环路优化设计实战

本文深入探讨了基于TL431与光耦的电压反馈环路优化设计实战。文章从理解这对“黄金搭档”的工作原理入手,详细拆解了电压采样电阻网络、偏置电路、光耦工作点设置以及动态补偿网络的设计心法与计算步骤。重点分享了如何通过RC补偿网络调试,确保环路在各种负载下稳定可靠,并提供了关键的实战避坑指南,帮助工程师解决电源设计中常见的振荡、噪声及可靠性问题。

nginx7reverse的博客 777

算法题解—并查集—好朋友

好朋友(算法题解) Description 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友 现在给出这些数码宝贝中所有好朋友的信息问:可以把这些数码宝贝分成多少组,满足每组中的任意两个数码宝贝都是好朋友,而且任意两组之间的数码宝贝都不是好

Archerrrrr的博客 515

基于wxWidgets框架,使用DialogBlocks建立OpenGL界面

前言 之前公司要求使用wxWidgets做GUI,基于OpenGL图形内核,开发三维可视化工具。目前初步开发工作基本已经完成,剩下都是完善了。这里记录一下最开始的框架搭建过程(当然是简化版啦)。wxWidgets结合OpenGL开发可以实现跨平台应用,再结合CMake和VS Code,整体开发工具用习惯了会感觉非常顺手。 界面编辑 首先,使用DialogBlocks新建一个工程,这里工程目录...

cyberobot的博客 2751

PAT- 并查集-好朋友

并查集的重点是维护一个father数组,来表明各结点间的关系 【好朋友】 1. 问题描述: 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那...

DedicateToAI的博客 457

系规备考论文:论IT服务规划设计

系规备考论文:论IT服务规划设计

liuxu324的博客 1145

【生信分析】clusterProfiler: universal enrichment tool for functional and comparative study(1)

clusterProfiler: universal enrichment tool for functional and comparative studyClusterProfiler: 用于功能和比较研究的通用富集工具总览1. 引言1.1 术语1.1.1 基因集和通路1.1.2 基因同源(GO)1.1.3 京都基因与基因组百科全书(KEGG)1.1.4 其他基因集2. 功能富集分析方法2.1 过度表征分析(Over Representation Analysis)2.2 基因集富集分析(Gene Se

小哲的博客 1366

(算法练习)——好朋友(并查集的使用)

注意点: 1、初始化,father[i] = i; 使每个节点先各自独立,输入为一组的话再合并(同时也符合根不同才能合并) 2、isRoot[i] = false;这是用来记录根节点的个数 《算法笔记》P332 #include <stdio.h> const int maxn = 110; int father[maxn]; bool isRoot[maxn]; int findf...

晴空 632

【WRF模拟】如何查看 WPS 的输入静态地理数据(二进制格式)?

如何查看 WPS 的输入静态地理数据(二进制格式)?

WW、forever的博客 633

好朋友(并查集)

好朋友 题目描述 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友 现在给出这些数码宝贝中所有好朋友的信息问:可以把这些数码宝贝分成多少组,满足每组中的任意两个数码宝贝都是好朋友,而且任意两组之间的数码宝贝都不是好朋友 输入格式 输入的第一行有

小李的博客 323

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PAT-并查集-好朋友

这个题是一个并查集的模型,可以把题目中的组视为“集合”,而题目中的好朋友关系视为边。那么在输入这些好朋友关系时就可以同时对他们进行并查集的合并操作。这样在处理完毕就能得到一些集合,而集合的个数就是要求的组数。 至于集合个数的求解,需要用到,“对于同一个集合来说,只存在一个根节点,且将其作为所属集合的标识”。因此可以开一个bool型数组flag[N]来记录每个结点是否作为每个集合的根结点,这样当处理完属兔数据之后,就可以遍历所有的元素,令它所在集合的根结点设置为true,最后累加flag数组中的元素,即可得.

资资的博客 243

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

并查集 - 好朋友

摘要:题目描述了一个数码世界,其中数码宝贝之间存在朋友关系。通过输入数码宝贝数量和朋友关系对,要求输出可以分成的互不相交的朋友组数。使用并查集算法来合并朋友关系,最终统计根节点数量即为答案。示例输入7个数码宝贝和5对朋友关系,输出3组,表明存在3个独立的朋友圈子。代码实现中运用了路径压缩优化查询效率。

whdehcy的博客 254

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

并查集例题-好朋友

/* 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝, 其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友, 而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友 现在给出这些数码宝贝中所有好朋友的信息问:可以把这些数码宝贝分成多少组, 满足每组中的任意两个数码宝贝都是好朋友,而且任意两组之间的数码宝贝都不是好朋友 */ #include&l

weixin_42616171的博客 144

并查集应用————好朋友

1 题目 Sample Inpu1t: 4 2 1 4 2 3 Sample Output1: 2 Sample Input2: 7 5 1 2 2 3 3 1 1 4 5 6 Sample Output2: 3 2 解析 2.1 题意 给出数码宝贝的个数与关系,给出数码宝贝分成的组数 2.2 思路 给出的组数实际为并查集的集合个数 1 用给出的关系建立并查集 2 用一个专门的数组查来记录...

韩江雪de 小屋 460

好朋友——并查集

分析:对于输入的每一对节点,他们一定在统一集合中,可以直接合并,这样最终会得到所有的连通图;每一个连通图都有根节点root 将根节点记录下来,将根节点数累加得到组数 #include <Iostream> using namespace std; const int maxn=110; int father[maxn]; int isroot[maxn]={0}; int findf...

One of thre_tigers的博客 468

并查集 好朋友

天勤书上一道题,很简洁的展现了并查集的思想。 大致意思是x和y是和朋友,xx和yy是好朋友......要你分组使组内都是好朋友,组外都不是好朋友。 数据量比较小,很水,路径压缩不考虑也没问题。 #include using namespace std; #define max 200 int father[max]; bool isroot[max]; void init(i

参与感 732

牛客小白月赛24 H.人人都是好朋友(离散化&并查集)

牛客小白月赛24 H.人人都是好朋友(离散化&并查集) 题目传送门 思路:将朋友的关系建立一个并查集。再遍历一遍,看两个敌人的根结点是否相同。 AC代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e6+5; #define mst(a) memset(a,0,...

Harris-H的博客 654

并查集&好朋友

并查集仅有一个根节点,因此设置isRoot[N]记录根节点的数目 #include<cstdio> const int N=110; int father[N]; bool isRoot[N]; int findFather(int x){ int a=x; while(x != father[x]){ x=father[x]; } //路径压缩 可省 //把 当前查询路径上的所有结点的的父亲都指向根结点 while(a != father[a]){ int z=a; .

juli_eyre的博客 217

并查集——好朋友

#include<stdio.h> const int maxn = 110; int father[maxn]; bool isRoot[maxn]; void init(int n) { for(int i = 1; i <= n; i++) { father[i] = i; isRoot[i] = false; } } int findFather(int x) { while(x != father[x]) { x = father[x]; } retu.

tian__si的博客 171

并查集模板题—好朋友

题目描述: 题目摘至《算法笔记》 分析: 此题为并查集的模板题,我们先来讲讲何谓并查集,顾名思义合并起来查找的集合,其实并查集可以这样理解(在此之前我们先来看看数组和链表的优缺点) 数组与链表的优缺点; 数组: 优点:使用方便 ,查询效率 比链表高,内存为一连续的区域 缺点:大小固定,不适合动态存储,不方便动态添加 链表: 优点:可动态添加删除 大小可变 缺点:只能通过顺次指针访问,查询效率低 而并查集正好结合了这两这的优点,使用方便,便于查询,且可以动态存储。下面我们来分

continue的博客 284

Kruscal&它的好朋友并查集

……我觉得我需要写一下并查集……毕竟我这么菜……不写篇博客过几天我都不知道自己学过  找爸爸  并查集了 但我这么菜,我也写不出太多东西……那就让这俩一起吧QwQ 反正kruscal也要用并查集的QwQ 并查集 并查集,俗称找爸爸(雾),就是多个集合之间的查询&amp;合并,具体操作包括:查询某两点是否在同一集合,合并某两点所在集合,以及一些鬼畜的操作 先贴代码,再说思想 int fi...

weiya040214的博客 228
上一篇: 并查集的基本操作
下一篇: 堆的基本操作
Estrellas_
博客等级 码龄9年 273粉丝 233原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值