F. AND Graph

Codeforces
IDCF987F
Time4000ms
Memory256MB
Difficulty
bitmasksdfs and similargraphs
English · Original
Chinese · Translation
Formal · Original
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\&$ is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). Count the number of connected components in that graph. ## Input In the first line of input there are two integers $n$ and $m$ ($0 \le n \le 22$, $1 \le m \le 2^{n}$). In the second line there are $m$ integers $a_1, a_2, \ldots, a_m$ ($0 \le a_{i} < 2^{n}$) — the elements of the set. All $a_{i}$ are distinct. ## Output Print the number of connected components. [samples] ## Note Graph from first sample: ![image](https://espresso.codeforces.com/2ae9959ec95b178e60e27e28f5d62c1099bb9ef1.png) Graph from second sample: ![image](https://espresso.codeforces.com/9f9eee8f2409bbd78cce726875915c405af8a07e.png)
给你一个大小为 $m$ 的集合,其中的整数元素在 $0$ 到 $2^n - 1$ 之间(包含两端)。我们按照以下方式构建一个无向图:当且仅当 $x & y = 0$ 时,在两个整数 $x$ 和 $y$ 之间连一条边。这里 $&$ 表示按位与运算。请计算该图中连通分量的数量。 输入的第一行包含两个整数 $n$ 和 $m$($0 lt.eq n lt.eq 22$,$1 lt.eq m lt.eq 2^n$)。 第二行包含 $m$ 个整数 $a_1, a_2, dots.h, a_m$($0 lt.eq a_i < 2^n$)——集合的元素,所有 $a_i$ 互不相同。 请输出连通分量的数量。 第一个样例的图: 第二个样例的图: ## Input 输入的第一行包含两个整数 $n$ 和 $m$($0 lt.eq n lt.eq 22$,$1 lt.eq m lt.eq 2^n$)。第二行包含 $m$ 个整数 $a_1, a_2, dots.h, a_m$($0 lt.eq a_i < 2^n$)——集合的元素,所有 $a_i$ 互不相同。 ## Output 请输出连通分量的数量。 [samples] ## Note 第一个样例的图: 第二个样例的图:
Let $ S \subseteq \{0, 1, \dots, 2^n - 1\} $ with $ |S| = m $, and define an undirected graph $ G = (S, E) $ where: $$ E = \{ \{x, y\} \mid x, y \in S,\ x \ne y,\ x \mathbin{\&} y = 0 \} $$ Count the number of connected components in $ G $.
Samples
Input #1
2 3
1 2 3
Output #1
2
Input #2
5 5
5 19 10 20 12
Output #2
2
API Response (JSON)
{
  "problem": {
    "name": "F. AND Graph",
    "description": {
      "content": "You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF987F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给你一个大小为 $m$ 的集合,其中的整数元素在 $0$ 到 $2^n - 1$ 之间(包含两端)。我们按照以下方式构建一个无向图:当且仅当 $x & y = 0$ 时,在两个整数 $x$ 和 $y$ 之间连一条边。这里 $&$ 表示按位与运算。请计算该图中连通分量的数量。\n\n输入的第一行包含两个整数 $n$ 和 $m$($0 lt.eq n lt.eq 22$,$1 lt.eq m lt.eq ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ S \\subseteq \\{0, 1, \\dots, 2^n - 1\\} $ with $ |S| = m $, and define an undirected graph $ G = (S, E) $ where:\n\n$$\nE = \\{ \\{x, y\\} \\mid x, y \\in S,\\ x \\ne y,\\ x \\mathbin{\\&} y = 0 \\}\n$$\n\nCount th...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments