首页 > 其他分享 >CF986C AND Graph

CF986C AND Graph

时间:2023-10-09 20:36:14浏览次数:32  
标签:typedef int Graph CF986C long 子集 include define

出题人纯nt要用bitset存bool数组来卡空间也真是没谁了

这题的思路其实有点像高维前缀和,考虑对于某个数\(x\),我们知道\(y=(2^n-1)\oplus x\)与\(x\)的与一定为\(0\),且\(y\)的所有子集也满足与\(x\)后为\(0\)

考虑怎么处理这种子集关系,我们借鉴于高维前缀和,每次把某个数\(y\)的某一位拿掉一个\(1\)后得到\(y'\),建边\(y\to y'\),这样可以在\(O(2^n\times n)\)的边数范围内得到一张代表了子集关系的图

因此这题的做法就很简单了,我们除了原图\(G\)之外再维护一个构造方式如上所述的图\(G'\)

  • 对于每个\(a_i\),将\(G\)中的\(a_i\)向\(G'\)中的\((2^n-1)\oplus a_i\)连边
  • 对于每个\(x\in G'\),除了连上述表示子集关系的边外,再向\(G\)中的\(x\)连边

最后直接DFS跑一下图中的连通块数量即可,总复杂度\(O(2^n\times n)\)

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_set>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=22;
int n,m,tot,a[(1<<N)+5],ans;
bitset <(1<<N)+5> c; bitset <(1<<N+1)+5> vis;
inline void DFS(int now)
{
	vis[now]=1; if (now<tot)
	{
		if (c[now]&&!vis[((tot-1)^now)+tot]) DFS(((tot-1)^now)+tot);
	} else
	{
		if (!vis[now-tot]) DFS(now-tot);
		auto lowbit=[&](int x)
		{
			return x&(-x);
		};
		for (int x=now-tot;x;x-=lowbit(x))
		if (!vis[((now-tot)-lowbit(x))+tot]) DFS(((now-tot)-lowbit(x))+tot);
	}
}
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (scanf("%d%d",&n,&m),tot=1<<n,i=0;i<m;++i) scanf("%d",&a[i]),c[a[i]]=1;
	for (i=0;i<m;++i) if (!vis[a[i]]) ++ans,DFS(a[i]);
	return printf("%d",ans),0;
}

标签:typedef,int,Graph,CF986C,long,子集,include,define
From: https://www.cnblogs.com/cjjsb/p/17753063.html

相关文章

  • Go - Creating Graphs
    Problem: Youwanttocreateaweightedgraphdatastructure.Solution: CreatestructsfornodesandedgesandplacetheminaGraphstruct.CreateandattachfunctionstoGraphtocreatenodesandedgesforthegraph. Graphsareverycommonnonlineard......
  • GraphPad Prism 9:探索科研医学数据的视觉传奇 mac+win版
    GraphPadPrism9,这不仅仅是一款数据绘图和分析软件,更是一款引领你走进科研医学世界的工具。无论你是科研工作者还是医学研究者,GraphPadPrism9都能帮你将复杂的数据转化为直观、精美的图表,为你的研究提供清晰的视觉呈现。→→↓↓载GraphPadPrism9mac/win版GraphPadP......
  • 成功解决WARNING: You do not appear to have an NVIDIA GPU supported by the 430.34
     https://blog.csdn.net/qq_41185868/article/details/97521492?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169682165516800215061872%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=169682165516800215061872&......
  • CodeForces 1876D Lexichromatography
    洛谷传送门CF传送门这说明你的能力还不足以维持IM。显然balanced的充要条件是,对于每个值,染色一定是RB交替。然后一种值只会有先染红或先染蓝两种情况。然后还剩下字典序严格小于的条件。我场上的想法是枚举\(\text{LCP}\),然后推出来一个巨大麻烦做法,根本写不出来。但......
  • Python程序调用图(Call Graph)
      vitsalis/PyCG:StaticPythoncallgraphgenerator(github.com)2103.00587.pdf(arxiv.org) PyCG-PracticalPythonCallGraphs PyCGgeneratescallgraphsforPythoncodeusingstaticanalysis.ItefficientlysupportsHigherorderfunctionsTwisted......
  • ControlNet-trt优化总结3:使用multi-stream和cuda-graph构建并行流水线
    ControlNet-trt优化总结3:使用multi-stream和cuda-graph构建并行流水线上节谈到使用TRT-API来构建网络,在这一节中总结一些trick来提升模型的运行效率,这些trick在所有的trt优化中均可使用,主要有以下几点:使用cuda_graph减少kernel间的启动间隙使用Mutil-stream增加异步cuda_gra......
  • 论文阅读:A Lightweight Knowledge Graph Embedding Framework for Efficient Inferenc
    ABSTRACT现存的KGE方法无法适用于大规模的图(由于存储和推理效率的限制)作者提出了一种LightKG框架:自动的推断出码本codebooks和码字codewords,为每个实体生成合适的embedding。同时,框架中包含残差模块来实现码本的多样性,并且包含连续函数来近似的实现码字的选择。为更好的提升K......
  • Langchain-Chatchat项目:2.1-通过GPT2模型来检索NebulaGraph
      在官方例子中给出了通过chain=NebulaGraphQAChain.from_llm(ChatOpenAI(temperature=0),graph=graph,verbose=True)来检索NebulaGraph图数据库。本文介绍了通过GPT2替换ChatOpenAI的思路和实现,暂时不考虑效果。之所以没用ChatGLM2是因为加载模型太慢,调试不方便,不过将GPT2......
  • CF506D Mr. Kitayuta's Colorful Graph
    好久没更新这个单题系列了,主要是最近没啥CF比赛空闲时间又少,今天忙里偷闲写了两个题这个题就比较典了,两点是否连通一般都是想到并查集维护,现在的问题是要对每种颜色的边把贡献算清楚很容易想到枚举所有颜色的边,每次求出所有连通分量后遍历一遍询问统计答案,这样正确性显然但复杂......
  • 构造Vulkan图形管线:VkGraphicsPipeline
     创建Pipeline构造信息:它包括:基本构造信息VkStructureType构建Pipeline额外需要的结构:constvoid*pNext构建Pipeline时指定的Flags:VkPipelineCreateFlags多个ShaderStage信息:VkPipelineShaderStageCreateInfo*(数组)......