半年前做的一道题现在还是不会

x&y=0

意味着,x的补集的子集都是和x直接相连的

不妨令图中的点数就是2^n

那么可以直接从x^((1<<n)-1)开始记忆化爆搜,路上遇到的都是和x直接相连的

如果遇到一个在给出集合里的数t,就从这个点额外再开一层,t^((1<<n)-1)再开始爆搜

这样,如果两个点直接或者间接相连,那么一定可以从任意一个点出发搜出整个连通块,并对每个点打上标记

总共的状态数是2^22。复杂度有保证

loc只是一个理解,其实不需要

#include<bits/stdc++.h>
using namespace std;
const int N=(<<)+;
int exi[N];
bool vis[N];// zuo i youwu vis
bool has[N];// you i youwu vis
int cnt,mx,len,up;
int a[N];
int n,m;
void dfs(int x,int loc){
//cout<<x<<" now "<<cnt<<endl;
if(loc){
if(has[x]) return;
has[x]=;
if(exi[x]) {vis[exi[x]]=;dfs(a[exi[x]],);}
for(int i=;(<<i)<=x;i++){
if(x&(<<i)){
dfs(x^(<<i),);
}
}
}
else{
vis[exi[x]]=;dfs(up^x,);
}
}
int main()
{
/*lg[0]=0;
for(int i=1;i<=N-5;i++) lg[i]=(i>>(lg[i-1]+1))?lg[i-1]+1:lg[i-1];*/
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d",&a[i]),exi[a[i]]=i,mx=max(mx,a[i]);
}
for(int i=;i<=;i++){
if((<<i)>mx) break;
len=i+;
}
up=(<<len)-;//cout<<" up "<<up<<endl;
for(int i=;i<=m;i++){
if(!vis[i]) {
//cout<<"here go "<<i<<" "<<a[i]<<endl;
cnt++;dfs(up^a[i],);
}
}
printf("%d",cnt);return ;
}

CF986C AND Graph的更多相关文章

  1. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  2. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  5. [LeetCode] Graph Valid Tree 图验证树

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  6. [LeetCode] Clone Graph 无向图的复制

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  7. 讲座:Influence maximization on big social graph

    Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...

  8. zabbix利用api批量添加item,并且批量配置添加graph

    关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...

  9. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

随机推荐

  1. C#_图片存取数据库Winform

    #region 用于在PictureBox控件中显示选择的图片        /// <summary>        /// 用于在PictureBox控件中显示选择的图片        ...

  2. Redis_简单使用

    可基于内存也可持久化的Key-Value(字典, Remote Dictionary Server,远程字典服务器)数据库. 客户端:http://redis.io/clients 命令:http:/ ...

  3. Redis未授权访问漏洞的利用及防护

    Redis未授权访问漏洞的利用及防护 什么是Redis未授权访问漏洞? Redis在默认情况下,会绑定在0.0.0.0:6379.如果没有采取相关的安全策略,比如添加防火墙规则.避免其他非信任来源IP ...

  4. MySQL的启动程序

    1.mysqld:             mysql server [root@test bin]# ./mysqld --user=mysql & [root@test bin]# ps ...

  5. CMake系列之四:多个源文件-多个目录

    多个源文件,多个目录 现在进一步将MathFunctions.c和MathFunctions.h文件移到math目录下: ./Demo3 | +--- main.c | +--- math/ | +- ...

  6. Java 类的加载

    package com.cwcec.p2; class C { public static final int SIZE; static { SIZE = 100; System.out.printl ...

  7. jQuery(六)

    $下常用方法 $().xxx:只能给jq对象用 $.xxx不仅可以给jq用也可以给原生js用,叫做工具方法 $.type() <script> $(function(){ var a= n ...

  8. PAT 1032 挖掘机技术哪家强

    https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032 为了用事实说明挖掘机技术到底哪家强,PAT组 ...

  9. Java abstract interface与 interface的区别

    我们常常遇到abstract class与 interface的区别,今天却遇到了abstract interface,感觉interface不用abstract再修饰了啊.结论:事实也确实如此,编译 ...

  10. MYSQL使用中字符编码一坑

    AJAX提交的字符出错,还以为是AJAX配置的错误呢!幸亏检查了一下MYSQL连接的字符集,发现开发库与本地库配置的字符集是也不一样的.