HDU 1272小希的迷宫 1325Is It A Tree? 并查集确定图为树

判断一个图是否为树(有向图以及无向图) http://www.cppblog.com/fm369o802340/archive/2012/12/10/196151.html 判断一个图是否为树 1. 无向图(hdu 1272 小希的迷宫) 2. 有向图(hdu 1325 Is It A Tree?) 题目大意:判断一个有向图是不是一棵树 判断条件:无环,一个根节点,(只有一个入度为0的结点,不存在入度大于1的结点) #include<iostream> #include<algorithm> #include<cst 阅读详情

这两题主要是解决一个图是否是树的问题。

有很多细节需要注意。

1、空树也是树。

2、一个图若是树需满足两个条件:

①连通分量为一;

②图中无环,包括自环和非自环。

3、边数+1=顶点数。

以上几点只是针对无向图的,1272题就是解决无向图是否是树的问题。而如果要判断有向图是否是树,还要判断

顶点的入度。满足入度为0的点只有一个,以及入度都不大于1。1325题就是判断有向图是否是树的问题。

 

1272   AC代码:

#include<iostream>
using namespace std;

const int MAX=100001;
int father[MAX];
bool flag[MAX],flagLC;

void initial()    //初始化
{
	for(int i=1;i<MAX;i++)
		father[i]=i;
}

int find(int x)    //查找
{
	while(father[x]!=x)
		x=father[x];

	return x;
}

void combine(int a,int b)   //合并
{
	int tmpa=find(a);
	int tmpb=find(b);

	if(tmpa!=tmpb)
		father[tmpa]=tmpb;
	else
        flagLC=true;    //a,b在同一个连通分量中,说明有环
}

int main()
{
	int i,a,b,connectedComponent,edgeNum,nodeNum;
	bool flagCircle;  //自环

	while(1)
	{
		initial();
		edgeNum=0;  //边数
		flagLC=flagCircle=false;   //标志是否有环
        memset(flag,false,sizeof(flag));   //标志在图内的点,在为true

        scanf("%d%d",&a,&b);

		if(a==0 && b==0)   //空树
		{
			cout<<"Yes"<<endl;
			continue;
		}

		if(a==-1 && b==-1) break;	
		if(a==b) flagCircle=true;

		flag[a]=true;
		flag[b]=true;
        edgeNum++;
        combine(a,b);	

		while(1)
		{
			scanf("%d%d",&a,&b);
			if(a==0 && b==0) break;
            if(a==b) flagCircle=true;

			flag[a]=true;
			flag[b]=true;
            edgeNum++;
			combine(a,b);
		}

		connectedComponent=0;        //连通分量数
        nodeNum=0;    //点数
		for(i=1;i<MAX;i++)   //判断图是否连通,tmp=1连通
		{
			if(flag[i])
			{
				nodeNum++; //计算图内包含的所有点
				if(father[i]==i)
					connectedComponent++;
			}
		}

		if(connectedComponent==1 && nodeNum==edgeNum+1 && !flagCircle && !flagLC)  //连通的无环图为树
			cout<<"Yes";
		else
			cout<<"No";
		cout<<endl;
	}

	return 0;
}


 

1325  AC代码:

#include<iostream>
using namespace std;

const int MAX=100001;
int father[MAX];
bool flag[MAX],flagLC;
int in[MAX];  //存放顶点入度

void initial()    //初始化
{
	for(int i=1;i<MAX;i++)
		father[i]=i;
}

int find(int x)    //查找
{
	while(father[x]!=x)
		x=father[x];

	return x;
}

void combine(int a,int b)   //合并
{
	int tmpa=find(a);
	int tmpb=find(b);

	if(tmpa!=tmpb)
		father[tmpa]=tmpb;
	else
        flagLC=true;    //a,b在同一个连通分量中,说明有环
}

int main()
{
	int i,a,b,connectedComponent,edgeNum,nodeNum,cas=1;
	bool flagCircle;  //自环

	while(1)
	{
		initial();
		edgeNum=0;  //边数
		flagLC=flagCircle=false;   //标志是否有环
        memset(flag,false,sizeof(flag));   //标志在图内的点,在为true
		memset(in,0,sizeof(in));

        scanf("%d%d",&a,&b);

		if(a==0 && b==0)   //空树
		{
			cout<<"Case "<<cas++<<" is a tree."<<endl;
			continue;
		}

		if(a<0 && b<0) break;	
		if(a==b) flagCircle=true;

		flag[a]=true;
		flag[b]=true;
        edgeNum++;
        combine(a,b);
		in[b]++;   //入度加1

		while(1)
		{
			scanf("%d%d",&a,&b);
			if(a==0 && b==0) break;
            if(a==b) flagCircle=true;

			flag[a]=true;
			flag[b]=true;
            edgeNum++;
			combine(a,b);
			in[b]++; //入度加1
		}

		connectedComponent=0;        //连通分量数
        nodeNum=0;    //点数
		for(i=1;i<MAX;i++)   //判断图是否连通,tmp=1连通
		{
			if(flag[i])
			{
				nodeNum++; //计算图内包含的所有点
				if(father[i]==i)
					connectedComponent++;
			}
		}

		int numZero=0,numMore=0;
		for(i=0;i<MAX;i++)
		{
			if(flag[i])
			{
				if(in[i]==0)  //入度为0的点即根只能有一个
					numZero++;
				else if(in[i]>1)   //不能有入度大于1的点
					numMore++;
			}
		}

		if(connectedComponent==1 && nodeNum==edgeNum+1 && !flagCircle && !flagLC && numZero==1 && numMore==0) //连通无环并且满足入度条件 
			cout<<"Case "<<cas++<<" is a tree.";
		else
			cout<<"Case "<<cas++<<" is not a tree.";
		cout<<endl;
	}

	return 0;
}


 


 

 

 

从零实现反激式电源仿真:LTspice高级应用实例 深入解析反激式开关电源的建模与仿真过程,利用LTspice实现从零搭建电路,精准验证电路仿真效果,提升电源设计效率与可靠性。 阅读详情

相关推荐

glibc手动升级高版本导致系统(RedHat/Centos)异常(无法开机等)的解决方法(回退低版本glibc)

我的系统是Redhat7.6, 理论上Redhat7/Centos7都可以使用该方法解决问题。 首先慎重提醒各位:glibc升级会产生无法预料的后果!由于Android NDK需要高版本的glibc才可以使用,所以作死手动去更新了glibc2.18,使得重启系统后图形界面消失。(Redhat/Centos升级此类安装包最好用yum升级,因为系统内的程序对他们的依赖很大,升级会导致大部分程序无法使用...

weixin_42881528的博客 9698

判定一个图为树

解题思路:首先此题是判断一个图是不是树,则这个图应该满足以下几个条件: 1、第一种情况是这个数为空树; 2、第二种情况为这棵树不为空树,在这个树中,(1)所有的节点最多有一个父节点(即指向这个节点的节点最多只有一个)(2)这棵树中不能存在环(3)这棵树中最多只能有一个根节点。

langzi989的专栏 1220

摄像头模组CCM简介

摄像头模组,全称Camera Compact Module,简写为CCM。CCM 包含几大件: 镜头(lens)、音圈马达(VCM)、传感器(sensor)、软板(FPC)、图像处理芯片(DSP)。工作原理:物体通过镜头(lens)聚集的光,通过CMOS或CCD集成电路,把光信号转换成电信号,再经过内部图像处理器(ISP)转换成数字图像信号输出到数字信号处理器(DSP)加工处理,转换成标准的GRB、YUV等格式图像信号。摄像头模组主要由以下几个部分组成:镜头(Lens):将光线汇聚到图像传感器上。

m0_73482095的博客 1万+

图11——判断图中是否为一棵树

编写算法,判断一个无向图是否是一颗树。 【分析】 一个无向图G是一棵树的条件为:G必须是无回路的连通图或n-1条边的连通图,这里我们采用后者作为判断条件。例如下图所示: 上面的无向图就是一棵树,它有6个顶点,5条边。 code: #include<stdlib.h> #include<stdio.h> #include<malloc.h> #inc...

凌空的桨 5414

深入解析:如何基于开源p-net快速开发Profinet从站服务

开源p-net协议栈为工业设备开发者打开了通往Profinet世界的大门。随着工业互联网的发展,软协议栈方案将在边缘计算领域展现更大潜力。该文章完整实现了PROFINET从站的核心功能,可直接作为产品开发的基础框架。实际部署时需根据具体硬件平台调整网络驱动和实时性配置。

极地星辰 3884

问题解决:打开VMware创建的虚拟机,电脑立刻蓝屏并重启

VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credenti

weixin_55118477的博客 3万+

判断图是否为树(C语言实现)

核心思想: 图是树需要满足两个条件: (1)图中结点均连通,即结点属于同一个集合; (2)结点满足只有一个结点入度为0,其余结点入度为1; 算法步骤: (1)一次读入一条边,将读入的边对相应的两个结点分别初始化,若该点之前不存在,则创建一个包含该点的新集合;同时,对于后面的结点,入度要进行加1; (2)比较该边的两个端点是否在同一个集合,若不在则将该边的两个端点所在的两个集合进行合并; (3)重复...

qq_42453280的博客 7534

2024年全国大学生电子设计竞赛H题_自动行驶小车

自动行驶小车(H题)【本科组/高职高专组】

qq_74395263的博客 1万+

HDU 1272:小希的迷宫 && HDU 1325:Is It A Tree?

HDU 1272:小希的迷宫判断图连通且无环即可。并查集水题,图连通说明整个集合只有一个代表,无环即插入的任何x,y。x,y不能属于同一集合。本题坑点,直接输入0 0属于空图,也要输出Yes。#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;cstring&gt; using namespace std; const...

温姑娘的博客 247

【个人学习总结】CRC校验原理及实现

CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定。循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将得到的结果附在帧的后面,接收设备也执行类似的算法,以保证数据传输的正确性和完整性。 ..................

星Yeah 的博客 7968

ZeroClaw安装、使用方法详细全解

ZeroClaw 是一个用 Rust 编写的轻量级、高性能、完全自主的 AI 助手运行时框架

洛星核的博客 618

HDU 1272 小希的迷宫 + 1325 Is It A Tree? , 并查集

题目链接: 小希的迷宫:http://acm.hdu.edu.cn/showproblem.php?pid=1272 Is It A Tree:http://acm.hdu.edu.cn/showproblem.php?pid=1325 题目类型: 并查集 题目: A tree is a well-known data structure that is eith

D_Double's Journey 1723

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDU 1325 Is It A Tree?(并查集)

题目大意:给你两个节点,前者指向后者(可以认为前者是后者的父节点),然后让你判断是否是一棵树。 解题思路:先说说这道题和小希的迷宫(HDU1272)那道题的区别,前者给出的两个点是有方向的,而后者是没有的,这就是唯一的区别。再者这道题其实就是让你判断所有的点最后所形成的图是否是一棵树。做这道题时错误了很多遍,细想之,主要是开始思路不好,很容易乱,理清思路让代码变得清晰起来就好了。判断一个图是否为

Ash.的博客 525

深度学习工具包 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")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU1325 Is It A Tree? 并查集

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1325 这题与HDU1272 小希的迷宫 (并查集) 非常像,不过细细看,还是有一点区别的。 就是这题的路径是单向的,每次只能由起点指向终点,在连接之前终点必须是根节点。 注意的问题: 1、不能成环,即每次输入的两个数的根节点不能相同; 2、最终根节点数目为一 3、注意当只输入“0 0” 时要输出”Case %d is a tree.“ 4、路径是单向的,即每次只能由起点指向终点,在连接之前终点必须是根节点。

旧时相识的专栏 649

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

HDU1325 Is It A Tree? + POJ1308 Is It A Tree?【并查集】

Is It A Tree? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16258    Accepted Submission(s): 3643 Problem Description A tree is a w

星尘 494

hdu 1325 Is It A Tree?

Is It A Tree?Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27615    Accepted Submission(s): 6375Problem DescriptionA tree is a well-known data...

路途遥远,初心难忘,道阻且长,愿君走出半生,归来仍是少年 265

杭电 hdu 1272 小希的迷宫 和 hdu 1325 Is It A Tree?(最下生成树 + 并查集)

杭电  hdu  1272   小希的迷宫   (最下生成树 + 并查集) 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33084    Accepted Submission(s): 101

thestarfish的博客 386

(简单并查集)hdu1325 Is It A Tree?

传送门:hdu1325 Is It A Tree? 一开始看到这题,感觉就是(判环-基础并查集)hdu1272 小希的迷宫 这题嘛??但是提交代码后一直wa,其实你仔细读题,可以提取出三个有关树的关键信息:   参考:https://www.cnblogs.com/wkfvawl/p/9671102.html...

200

HDU-1325-Is It A Tree?

ACM模版描述题解这道题方法很多,比较好的方法是直接根据树的性质来判断,先判断是否有环,可以通过边数来判断,n个结点最多有n-1条边,不然一定会有环,接着判断根的个数,也就是入度为0的个数,必须为1,最后判断其他根节点入度是否都为1,否则说明不是树!当然,判断环的部分也可以用并查集,但是这个并查集需要注意些剪枝优化,不然会TLE的,我一开始直接拿着小希的迷宫的代码改了一行提交,TLE了两次……怪我太

逐梦者 607

HDU - 1325 Is It A Tree?

Is It A Tree? Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status]   Description A tree is a well-known data stru

acm_1361677193的专栏 325

Is It A Tree?

Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26762   Accepted: 9132 Description A tree is a well-known data structure that is either empty (

My_Fresh_Start的博客 570

HDU1232 畅通工程 并查集

这题是并查集的简单运用。我所利用的并查集没有经过优化。只用到了初始化(每个元素都是一个集合)、查找(某个 元素所在的集合,集合以根节点标志)、合并(两集合不属于同一集合则合并) 这题的主要思想在于:找出连通分量的个数。减一之后就是所求最小需要添加的路径数。而利用并查集时可以发现连通 分量的个数等于父节点为自身的节点数目。   AC代码: #include using namespac

ON THE WAY TO GEEK 5622
上一篇: HDU1232 畅通工程 并查集
下一篇: HDU 1068 Girls and Boys 二分图 最大独立集 字符串
lulipeng_cpp
博客等级 码龄15年 169粉丝 130原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值