Codeforces Round #599 (Div. 2) D.0-1 MST(补图连通块/并查集)

经典算法:求解补图的连通块 模板题:CF1243 D. 0-1 MST 解法一:思维,并查集 从小到大遍历节点。set动态维护当前已有连通块。对于每新增的一个节点iii,我们试图用它来合并这些已有的连通块。具体做法就是用map记录它到每个连通块的边数。当连接边数 < 连通块点数时,合并iii与这个连通块。连完清空set,再重新更新最新父节点. 复杂度分析: 乍看复杂度很高,但是均摊下来可以接受。 对于每个新增节点,复杂度来源于两个方面:1. map统计到每个集合个数 2.遍历当前连通块。 1这个部分就是w 解法二:BFS .. 阅读详情

题目

给一个n(n<=1e5)个,点m(m<=n*(n+1)/2)条边的图,

图本是完全图,这m条边的代价都为1,其余的边的代价都为0,

求这个图的最小生成树的代价,输出代价

思路来源

官方题解

题解1

考虑把0边的在并查集都合在一起,忽略1边,就变成了补图x个连通块,

使x个联通块相同必须用1的代价,答案即补图连通块个数-1,

一条边只在点号大的时候考虑一次,对于一个给定点u,

如果u连向另一连通块v的1边的个数now[v]比这个连通块的大小sz[v]要小,

说明u一定有0边连向这个连通块v,即合并u和v的集合

检查所有边,每次并查集合并复杂度logn,总复杂度大概O(nlogn+m)

代码1

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,mod=1e9+7;
int n,m,u,v,x,y;
int sz[N],par[N];
int rt[N],tot,num;//rt[]:满足par[i]==i的集合 
int now[N],ans;//now[i]:现在的点的个数 
vector<int>e[N];
int find(int x)
{
	return par[x]==x?x:par[x]=find(par[x]);
}
int main()
{
	//求补图连通块的块数 
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		par[i]=i;
		sz[i]=1;
	}
	for(int i=1;i<=m;++i)
	{
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	} 
	for(int i=1;i<=n;++i)
	{
		for(int v:e[i])
		{
			if(v>i)continue;
			now[find(v)]++;
		}
		for(int j=1;j<=tot;++j)//1-tot为已出现的点 rt[j]为现存的根 
		{
			x=find(rt[j]);
			y=find(i);
			if(x==y)continue;
			if(sz[x]>now[x]) 
			{
				par[y]=x;
				sz[x]+=sz[y];
			}
		}
		num=0; 
		for(int j=1;j<=tot;++j)
		if(find(rt[j])==rt[j])rt[++num]=rt[j];
		if(find(i)==i)rt[++num]=i;
		tot=num;
		for(int v:e[i])
		{
			if(v>i)continue;
			now[find(v)]=0;
		}
	}
	for(int i=1;i<=n;++i)
	if(find(i)==i)ans++;
	printf("%d\n",ans-1);
	return 0;
} 

题解2

做法是bfs,set维护当前没有确定集合的点,确定了一个点即将其删掉,

此做法复杂度比较玄学,据说均摊O(nlogn+nlogm)

其实不是愁没有做法,只是不敢莽啊,分析不出确切复杂度,参考一下qls的代码吧

但感觉好像最坏情况应该是sqrt个块,每个内部完全图的情形,这样好像也只是nsqrt(n)的样子?

#include<bits/stdc++.h>
using namespace std;
const int MAXN=200005;
bool vis[MAXN],ban[MAXN];
list<int> fre;
vector<int> e[MAXN];
int bfs(int st)
{
    int res=0;
    queue<int> q;
    q.push(st);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(vis[u])continue;
        vis[u]=1,res++;
        for(auto &v:e[u])ban[v]=1;
        for(auto itr=fre.begin();itr!=fre.end();)
        {
            int v=*itr;
            if(!ban[v])
            {
                q.push(v);
                fre.erase(itr++);
            }
            else itr++;
        }
        for(auto &v:e[u])ban[v]=0;
    }
    return res;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fre.push_back(i);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    vector<int> con;
    for(int i=1;i<=n;i++)
        if(!vis[i])con.push_back(bfs(i));
    sort(con.begin(),con.end());
    printf("%d\n",(int)con.size()-1);
    return 0;
}

 

工业相机图像格式深度解析:从Mono8到Mono12的选型与应用 本文深度解析工业相机黑白图像格式,重点对比Mono8、Mono10与Mono12的核心差异。文章从位深、动态范围和数据量等关键概念切入,详细阐述了不同格式的优缺点及适用场景,为工业视觉项目中的相机选型提供实战指南,帮助用户在精度、速度与成本间做出最优决策。 阅读详情

相关推荐

从零到一:RagFlow源码架构深度解析与二次开发实战指南

本文深入解析RagFlow源码架构,提供从环境搭建到二次开发的全流程实战指南。作为企业级AI搜索框架,RagFlow通过模块化设计和多模态处理能力,支持自定义智能体开发与文搜文档功能,帮助开发者高效构建智能搜索系统。

w1x2y3的博客 270

(hdu step 6.1.4)还是畅通工程(求让n个点联通的最小费用)

题目:还是畅通工程Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 165 Accepted Submission(s): 127 Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程

黄俊东的专栏 1343

Drools vs URule:5个真实项目场景告诉你如何选择开源规则引擎

本文通过电商风控、物流计费、会员体系、保险定价和物联网告警五个真实项目场景,深度对比了Drools与URule两款开源规则引擎。分析了两者在规则复杂度、性能表现、开发运维及适用场景上的核心差异,为技术选型提供基于实战的决策指南。

k6l7m8n9的博客 952

codeforces 1242B 0-1 MST 【图论+并查集】

题目分析 要求最小生成树,如果考虑有0 边相连的点作为一个集合的话,那么就是求集合的个数 那么我们怎么统计 有 0边相邻的点呢? 很显然不能再原图上直接暴力跑。因为随着n的增大,补图会非常大。 但是我们用并查集维护集合的个数 那么我们考虑一个点u ,遍历与u相邻的所有小于u的点,统计u与这个点所在的集合相连的数量 比如 1,2,3 是一个集合 6 与1,2,相连,那么1,2,3 这个集合的数量为3...

beckyUp的博客 881

OTN传送网实战指南:从光层到电层的完整架构解析(附配置示例)

本文深入解析OTN传送网从光层到电层的完整架构,涵盖关键组件、技术实现及配置示例。通过高速公路与光传送网的类比,详细介绍了光层超宽传输管道构建、电层业务调度核心引擎以及控制平面智能运维实战。附有典型组网方案与故障排查指南,助力网络工程师高效部署与维护OTN传送网。

tomato的博客 692

fMRI脑影像特征提取——静息态与任务态,ALFF/fALFF和ReHo(Dpabi,Rest1.8)

任务态和静息态是大脑的两种状态,前者主要是指大脑在执行记忆、识别以及运动等具体任务时的状态,静息态则是指大脑不执行具体认知任务、保持安静、放松、清醒时的状态,是大脑所处的各种复杂状态中最基础和最本质的状态。任务态fMRI分析有非常悠远的历史,而静息态fMRI自1995年biswal教授及其同事率先报告静息态fMRI具有生理意义后,越来越多的人进入了静息态的研究领域。任务态fMRI主流的分析方法是模型驱动(GLM+HRF),也可以引用静息态fMRI

意疏的学习笔记 6万+

Codeforces 1243D 0-1 MST(补图的连通图数量)

思路: 1.没有给出的边权值都为0,因此就是求补图的连通图数量-1; 2.从1遍历到n,假设遍历到i,我们求出i所在的连通图的其它点,并做上标记,在遍历时,就跳过做完标记的点,遍历了ans次,就说明有ans个连通图; 3.如何求出i所在的连通图的其它点呢?我们用双链表存储未被遍历过的点(节省时间),遍历和i相连权值为1的边,如果边的另一个端点未被遍历过,我们就做一个标记,接着遍历所有未被遍历过的...

Yuhan的博客 357

qtcreator使用远程服务器编译代码

我并没有找到很好的windows上可以用的rsync工具,最后是装了wsl来调用rsync同步到代码后,在用ssh调用linux命令来编译的。安装wsl安装ubuntu启动wsl然后把windows里的ssh文件证书和配置复制到wsl里同时config的key目录需要改一下,这样就可以登录服务器了然后在home目录创建build.sh进行远程编译。

习惯就好zz的专栏 1393

cf #599 (Div. 2) D 0-1 MST

题目链接 题意:给你一个图,有n个节点,m条边,如果两个节点之间有边,则边权值为1,否则这两个节点之间的边权值为0。求这个图的最小生成树的边权值的和。 思路:求这个图的逆向图的联通块的个数,答案就是个数减1,因为n个联通块只需要n-1条线段就可以变成一个联通块,而对于每个联通块来说,任意两点的边权都是0,可以默认看成一棵树。如何求出联通块的个数,用一个set-s保存每个节点的编号,set-G...

我是蒋卫升呀~ 231

用 ABAP OAuth 2.0 Client 直连 SAP SuccessFactors:从体系到落地的一条龙实践指南

ABAP SMI允许在后端对外部服务的OData端点进行定义与自定义化配置,并以受信连接的方式暴露给ABAP应用调用。它并不替代OAuth,而是扮演端点与自定义参数的集中化定义者,最终认证依旧由完成。对于需要在ABAP后端发起临时或补充型OData调用的场景,SMI是一个轻量而清晰的集成入口。scope的客户端应用已经完成注册,API DomainCompany ID、证书或密钥都已归档。ABAP的Profile与Client已建立并绑定,OA2C_GRANT可见绿色访问状态。SMI。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 288

[DevExpress]GridControl拖拽行记录排序

DevExpress的GridControl拖拽行记录排序需求效果代码 需求 现在用户对按钮点击排序不满意了, 希望拖拽排序。 重载GridControl控件,对MouseMove、MouseDown、MouseUp事件修改一下。 效果 代码 using System; using System.Drawing; using System.Windows.Forms; using xiaoid.forms; using System.Data; using System.Collections.Gener

德仔 1565

Codeforces Round #599 (Div. 2) DE题解

D. 0-1 MST 题意:给一个无向图,如果u,vu,vu,v有边相连,那么他们的边权为1,否则为0,求最小生成树 解法:不难发现最小生成树权值其实可以转化为该无向图的补图的联通块个数减一,那我们就来求补图联通快好了,我们用一个setsetset存所有没有用过的点,我们开始任意选择一个setsetset里的点开始bfsbfsbfs,假设出队的点为uuu,我们枚举setsetset的点vvv,如...

ccsu_cat 555

7、初级视觉皮层(V1)的研究综述

本文综述了初级视觉皮层(V1)的基本功能特性、计算理解、细胞相互作用及理论模型。V1不仅执行方向和空间频率的选择性滤波,还通过相位选择性和上下文调制参与高级视觉处理。研究从信息编码角度解释了V1感受野的形成,并介绍了基于自然图像统计的建模方法。横向与反馈连接揭示了V1在全局视觉整合中的作用,尤其是上下文对细胞响应的快速调节。李的动态模型提出V1可生成视觉显著性图,支持前注意分割和注意力引导。未来研究聚焦于V1在注意力、意识和硬件实现中的潜在应用,推动视觉神经科学与人工智能的交叉发展。

7z8x2c4v6b9的博客 147

Codeforces Round #599 (Div. 2) 题解

题目链接:https://codeforces.com/contest/1243 A - Maximum Square 水题不说了 #include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 50; typedef long long ll; int n; int a[mx]; int main(...

过路人丶的博客 355

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Codeforces Round 599 (Div. 1+2)___D. 0-1 MST —— 链表优化 BFS

题目链接:点我啊╭(╯^╰)╮ 题目大意:     nnn 个点的完全图     给出 mmm 条边,边权为 111,0≤m≤min(n(n−1)2,105)0≤m≤min( \frac{n(n−1)}{2},10^5)0≤m≤min(2n(n−1)​,105)     其他边权...

Scar_Halo 330

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforce round 599 D. 0-1 MST (补图+BFS+思维)

题目链接:https://codeforces.com/contest/1243/problem/D 题目大意: 给定一个n节点的完全图(n<=1e5),现在给出m条边权为1的边(m<=min(n*(n-1)/2,1e5)),其余的边权值为0,问你这个图的最小生成树的权值大小是多少? 题目思路: 很明显,如果我们考虑边权为0的边并去掉边权为1的边,那么答案就是边权为0的边组成的...

Q755100802的博客 246

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Codeforces Round #599 (Div. 2) ---C. Tile Painting+D. 0-1 MST(补图的连通图的个数)

C: 当n=p^k时,可知答案为k. 当n=p*q时,对于 x=i (mod p) x=j (mod q) 根据CRT,在n以内方程组一定有解,那么可知,此时所有i,j的颜色都相同。 D: 刚开始看题,没有一点思路,直到看了一眼题解后,马上就明白了。由于边权的特性,所以要想求出MST的权值,只要尽可能的多用0的边即可。而题目给了1的边,那么只要求出补图中的连通块的个数即可,然后用1的边连接即可。所...

weixin_43184669的博客 262

Codeforces Round #599 (Div. 2)

菜鸡终于上分,b2极限a题,我都以为要错,哈哈。 A Maximum Square 水题 #include <bits/stdc++.h> using namespace std; #define ll long long #define debug(x, y) cout <<x<<" "<<y<<endl #define nl en...

weixin_44070289的博客 187

Codeforces Round #599 (Div. 1) B. 0-1 MST(图论+dfs)

题目链接 思路:答案很容易想到就是非直连边的连通块的数量-1,这题难就难在你想到了,但你不会实现。。。 vis一开始存的是所有点,temp存的就是与当前点x的非直连点,每次dfs到一个点的时候就将与他非直连点从vis里删除。 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+1; set<int...

qq_42479630的博客 244

Codeforces Round #599 (Div. 2)补题

题目 文章目录A - Maximum SquareB1 - Character Swap (Easy Version)B2 - Character Swap (Hard Version)C - Tile PaintingD - 0-1 MSTE - Sum Balance A - Maximum Square #include<bits/stdc++.h> using namespac...

qq_44290978的博客 267

CF-round#599-1242

图论-BFS 题目:0-1 MST 链接:https://codeforces.com/contest/1242/problem/b 大意:给你一张完全图,n<=1e5个结点,其中最多有m<=1e5条边权为1的边,剩余的边边权全为0 分析:求无向补图最少构成几个连通分量:如果不是补图,那我们就直接BFS了,。。。。然而不是补图还是只能BFS,但BFS的方法要发生变化,原...

qq_41046771的博客 291

Codeforces Round #599A~D题解

Maximum Square 这是一道很简单的题目大意就是说给你一个几个木棍拼成一串问你从中扣出一个正方形的最大边长是多少 二分简单枚举一下可能的长度再判断一下就好了 #include <iostream> #include <algorithm> using namespace std; const int N = 1e3 + 10; int k, T; int a[N...

weixin_45630722的博客 191

CodeForces 1417 F Graph and Queries 无向图连通块问题转化为树上问题 重构树

link 题意:给一无向连通图,每个点有一个权值,q次操作 每次操作有两种 1,v 寻找v所在连通块内权值最大的点,并输出这个权值并且把改点权值变成0 2.x 删掉第i条边 思路: 查询图上连通块内最大值和修改我们只学过在一棵树上利用dfs序,然后线段树维护。 那么考虑如何将此题转化成一棵树。 我们把删边考虑为倒着加边。在加边过程中利用并查集维护连通块。并且将每一时刻每一个点的连通块转化为一颗’子树’,这样在查询的时候就可以通过查询子树点权最大值来得到结果。 如何将各个时刻的连通块转化为一颗树? 只需要在加

qq_43914084的博客 1047

【codeforces 1243】D. 0-1 MST(补图的连通块计数)

题意: 给你一个图,求补图的联通块个数。 题解: 考虑用使用并查集,用set存已经被放入并查集的点,对于没有放入的点,计算该点和联通块相连的点的个数,如果相连的点的个数小于联通块大小,则直接连进去即可。时间复杂度O(n+m∗log)O(n+m*log)O(n+m∗log)。 代码: #include<bits/stdc++.h> using namespace std; const...

duanghaha的博客 821

有向图无向图判断有环(求环的长度)

东北地区赛有个无向图判自环的题当时没苟出来,回来之后想了想用并查集可以实现,然后仔细查了一波还有哪些方法…… 总结一波博客吧QAQ…… 资源来源: https://blog.csdn.net/ouyangruo/article/details/51057409 https://blog.csdn.net/acmdream/article/details/72983715 http://w...

小衣同学的博客 5774
上一篇: Codeforces Round #605 (Div. 3) 补题(E最短路/多源bfs、Fdp+输出路径)
下一篇: hdu4578 Transformation(线段树/区间加区间乘区间赋值区间立方和)
小衣同学
博客等级 码龄9年 1444粉丝 995原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址