不难想到,x有边连出的一定是 (2^n-1) ^ x 的一个子集,直接连子集复杂度是爆炸的。。。但是我们可以一个1一个1的消去,最后变成补集的一个子集。

但是必须当且仅当 至少有一个 a 等于 x 的时候, 可以直接dfs(all ^ x) ,否则直接消1连边。。。

Discription

You are given a set of size mm with integer elements between 00 and 2n−12n−1 inclusive. Let's build an undirected graph on these integers in the following way: connect two integers xx and yy with an edge if and only if x&y=0x&y=0. Here && is the bitwise AND operation. Count the number of connected components in that graph.

Input

In the first line of input there are two integers nn and mm (0≤n≤220≤n≤22, 1≤m≤2n1≤m≤2n).

In the second line there are mm integers a1,a2,…,ama1,a2,…,am (0≤ai<2n0≤ai<2n) — the elements of the set. All aiai are distinct.

Output

Print the number of connected components.

Examples

Input
2 3
1 2 3
Output
2
Input
5 5
5 19 10 20 12
Output
2

Note

Graph from first sample:

Graph from second sample:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=5000005;
int ci[233],T,n,a[maxn],ans,all;
bool v[maxn],isp[maxn]; inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} void dfs(int x){
if(v[x]) return;
v[x]=1; if(isp[x]) dfs(all^x); for(int i=0;i<=T;i++) if(ci[i]&x) dfs(x^ci[i]);
} inline void solve(){
for(int i=1;i<=n;i++) if(!v[a[i]]){
ans++,v[a[i]]=1,dfs(all^a[i]);
}
} int main(){
ci[0]=1;
for(int i=1;i<=22;i++) ci[i]=ci[i-1]<<1; T=read(),n=read(),all=ci[T]-1;
for(int i=1;i<=n;i++) a[i]=read(),isp[a[i]]=1; solve(); printf("%d\n",ans);
return 0;
}

  

CodeForces - 986C AND Graph的更多相关文章

  1. Codeforces 986C AND Graph dfs

    原文链接https://www.cnblogs.com/zhouzhendong/p/9161514.html 题目传送门 - Codeforces 986C 题意 给定 $n,m (0\leq n\ ...

  2. Codeforces 986C - AND Graph(dfs)

    Codeforces 题面传送门 & 洛谷题面传送门 考虑 DFS 一遍遍历每个连通块. 当我们遍历到一个点 \(x\) 时,我们就建立一个虚点 \((2^n-1-x)'\) 表示我们要访问 ...

  3. Codeforces 1093D Beautiful Graph(二分图染色+计数)

    题目链接:Beautiful Graph 题意:给定一张无向无权图,每个顶点可以赋值1,2,3,现要求相邻节点一奇一偶,求符合要求的图的个数. 题解:由于一奇一偶,需二分图判定,染色.判定失败,直接输 ...

  4. Codeforces 466E Information Graph

    Information Graph 把询问离线之后就能随便搞了, 去check一下是不是祖先, 可以用倍增也能用dfs序. #include<bits/stdc++.h> #define ...

  5. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  6. Codeforces 1288F - Red-Blue Graph(上下界网络流)

    Codeforces 题面传送门 & 洛谷题面传送门 好久没有写过上下界网络流了,先来一题再说( 首先先假设所有边都是蓝边,那么这样首先就有 \(b\times m\) 的花费,但是这样不一定 ...

  7. CodeForces 466E Information Graph --树形转线性+并查集

    题意:有三种操作: 1.新增一条边从y连向x,此前x没有父节点 2.x接到一份文件,(文件标号逐次递增),然后将这份文件一路上溯,让所有上溯的节点都接到这份文件 3.查询某个节点x是否接到过文件F 解 ...

  8. 【CodeForces 624C】Graph and String

    题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...

  9. codeforces 165D.Beard Graph 解题报告

    题意: 给一棵树,树的每条边有一种颜色,黑色或白色,一开始所有边均为黑色,有两个操作: 操作1:将第i条边变成白色或将第i条边变成黑色. 操作2 :询问u,v两点之间仅经过黑色变的最短距离. 树链剖分 ...

随机推荐

  1. 一些比较高效的CSS写法建议

    当浏览器解析html的时候,它构造了一个文档树来展现所有被显示的元素. 它在特定的样式表中去匹配元素,根据标准的css的层叠,继承和顺序规则, 在mozilla的实现中(可能其他的也是这样),对于每一 ...

  2. bzoj2442&&codevs4654 单调队列优化dp

    这道题也是一道单调队列 很明显满足各种性质 f[i]表示i不选前面k-1个都选的最小损失 维护的是个单增队列 q[head]是队列最小值 代码十分简介 注意longlong就okay #include ...

  3. 【Codeforces】849D. Rooter's Song

    [算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...

  4. 地震(quake)

    地震 题目描述 一场地震毁了 Farmer John 的整个农场.他是个有恒心的人,决定重建农场.在重建了所有 n(1<=n<=400)块田野后,他意识到还得修路将它们连起来.完工后,任两 ...

  5. python自带的线程池和进程池

    #python自带的线程池 from multiprocessing.pool import ThreadPool #注意ThreadPool不在threading模块下 from multiproc ...

  6. shell脚本之while for if 语句和编写计划任务

    关于while循环: while do done 例如 1.关于内存的实时操作: (1).vim a.sh (2).输入以下while循环 (3)../a.sh执行脚本 2.自加一的操作: (1).v ...

  7. Swift教程之运算符重载

    http://blog.csdn.net/mengxiangyue/article/details/43437797 原文地址:http://www.raywenderlich.com/80818/o ...

  8. 安全测试===BurpSuite使用教程-附安装包

    jar包: Burpsuite1.6亲测可用.zip 我的jdk版本: 运行包: >>> java -cp BurpLoader.jar;burpsuite_pro_v1.6.jar ...

  9. Spring容器整合WebSocket

    原链接:http://blog.csdn.net/canot/article/details/52575054 WebSocker是一个保持web客户端与服务器长链接的技术.这样在两者通信过程中如果服 ...

  10. 6.shell判断语句

    [ condition ](注意condition前后要有空格),可以使用$?验证(0为true,>1为false) 两个整数的比较:=:字符串比较-lt:小于-gt:大于-le:小于等于-ge ...