Colorful WorksAI (CI翻译)
Gold14526 is a painter. He can paint with $n$ colors, numbered $1, 2, \ldots, n$. Color $i$ has a constraint interval $[l_i, r_i]$.
A work is defined as a rooted tree $T=(V,E)$ where every edge is colored (with one of the $n$ colors). A work is called colorful if the following conditions are satisfied:
- For any three nodes
$u, v, w \in V$, if edges$(u,v)$and$(v,w)$both exist, they must have different colors. - For all colors
$i \in [1,n]$, let$d(u,i)$denote the number of edges of color$i$on the simple path from node$u$to the root. Then$\max_{u \in V} d(u,i) \in [l_i, r_i]$.
Two works $T=(V,E)$ and $T'=(V',E')$ are defined as isomorphic if and only if the following two conditions are met:
$\lvert V\rvert = \lvert V'\rvert$;- There exists a bijection
$f:V \to V'$such that: - Let
$r$be the root of$T$and$r'$be the root of$T'$. Then$f(r) = r'$;- For any
$(u,v) \in E$, we have that$(f(u),f(v)) \in E'$, and the color of edge$(u,v)$is the same as the color of edge$(f(u),f(v))$.
- For any
Gold14526 wants to know the maximum number of colorful works he can choose such that the works are pairwise non-isomorphic. Output the answer modulo $\bf2$.
Input
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($1\le n\le 2\cdot 10^6$) — denoting the number of colors.
The following $n$ lines each contain two integers, the $i$ -th of them $l_i$ and $r_i$ ($0\le l_i\le r_i\le 2\cdot 10^5$, $r_i\ge 1$) — denoting the constraint interval of the $i$ -th color.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^6$.
Let $m=\max_{i=1}^n r_i$. Then it is guaranteed that the sum of $m$ over all test cases does not exceed $2\cdot 10^5$.
Output
For each test case, output $0$ or $1$, representing the maximum number of works that can be chosen modulo $2$.
Note
In the first test case, the constraints for both colors are $[0, 1]$. This means on any simple path from the root, there can be at most $1$ edge of color $1$ and at most $1$ edge of color $2$. There are exactly $9$ valid pairwise non-isomorphic trees:
$1$tree with$1$node: just the root.$2$trees with$2$nodes: the root is connected to a child by an edge of color$1$, or by an edge of color$2$.$3$trees with$3$nodes:- the root is connected to two children by edges of color
$1$and$2$respectively.- a path of
$2$edges from the root, colored$1$then$2$. - a path of
$2$edges from the root, colored$2$then$1$.
- a path of
$2$trees with$4$nodes:- the root has a child via color
$1$(which further has a child via color$2$), and another child via color$2$.- the root has a child via color
$2$(which further has a child via color$1$), and another child via color$1$.
- the root has a child via color
$1$tree with$5$nodes: the root is connected to two children by colors$1$and$2$, and each of these children has exactly one child of the opposite color.
Since $9 \equiv 1 \pmod 2$, the output is $1$.
In the second test case, the constraints for both colors are $[1, 1]$. Every valid tree must satisfy the maximum count of each color on the paths to be exactly $1$. Therefore, the tree must contain at least one edge of color $1$ and at least one edge of color $2$. There are exactly $6$ valid trees:
$3$trees with$3$nodes: the root connected to two children by colors$1$and$2$; a path colored$1$then$2$; a path colored$2$then$1$.$2$trees with$4$nodes: same as the two$4$-node trees described in the first test case.$1$tree with$5$nodes: same as the$5$-node tree described in the first test case.
Since $6 \equiv 0 \pmod 2$, the output is $0$.
{"titleZh":"彩色作品","bodyZh":"Gold14526 是一名画家。他可以使用 $n$ 种颜色,编号为 $1, 2, \\ldots, n$。颜色 $i$ 有一个约束区间 $[l_i, r_i]$。\n\n一个作品定义为一棵有根树 $T=(V,E)$,其中每条边都被涂上某种颜色(共 $n$ 种颜色之一)。如果满足以下条件,则称一个作品是彩色的:\n\n- 对于任意三个节点 $u, v, w \\in V$,如果边 $(u,v)$ 和 $(v,w)$ 都存在,那么它们的颜色必须不同。\n- 对于所有颜色 $i \\in [1,n]$,令 $d(u,i)$ 表示从节点 $u$ 到根的简单路径上颜色为 $i$ 的边数。那么 $\max_{u \\in V} d(u,i) \\in [l_i, r_i]$。\n\n当且仅当以下两个条件都满足时,称两个作品 $T=(V,E)$ 和 $T'=(V',E')$ 同构:\n\n- $\\lvert V\\rvert = \\lvert V'\\rvert$;\n- 存在一个双射 $f:V \\to V'$,使得:\n- 设 $r$ 是 $T$ 的根,$r'$ 是 $T'$ 的根,则 $f(r) = r'$;\n - 对于任意 $(u,v) \\in E$,都有 $(f(u),f(v)) \\in E'$,并且边 $(u,v)$ 与边 $(f(u),f(v))$ 的颜色相同。\n\nGold14526 想知道他最多可以选择多少个彩色的作品,使得这些作品两两不同构。输出答案对 2 取模后的结果。\n\n## 输入格式\n\n每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来是各个测试用例的描述。\n\n每个测试用例的第一行包含一个整数 $n$($1\\le n\\le 2\\cdot 10^6$),表示颜色的数量。\n\n接下来的 $n$ 行中,第 $i$ 行包含两个整数 $l_i$ 和 $r_i$($0\\le l_i\\le r_i\\le 2\\cdot 10^5$,$r_i\\ge 1$),表示第 $i$ 种颜色的约束区间。\n\n保证所有测试用例的 $n$ 之和不超过 $2\\cdot 10^6$。\n\n令 $m=\\max_{i=1}^n r_i$。保证所有测试用例的 $m$ 之和不超过 $2\\cdot 10^5$。\n\n## 输出格式\n\n对于每个测试用例,输出 $0$ 或 $1$,表示最多可以选择的作品数量对 $2$ 取模后的结果。\n\n## 说明\n\n在第一个测试用例中,两种颜色的约束均为 $[0, 1]$。这意味着从根出发的任意简单路径上,颜色 $1$ 的边数至多为 $1$,颜色 $2$ 的边数也至多为 $1$。恰好存在 $9$ 棵有效且两两不同构的树:\n\n- $1$ 棵树有 $1$ 个节点:只有根节点。\n- $2$ 棵树有 $2$ 个节点:根通过颜色 $1$ 或颜色 $2$ 的边连接到一个子节点。\n- $3$ 棵树有 $3$ 个节点:\n- 根分别通过颜色 $1$ 和颜色 $2$ 的边连接到两个子节点。\n - 从根出发、边数为 $2$ 的路径,颜色依次为 $1$、$2$。\n - 从根出发、边数为 $2$ 的路径,颜色依次为 $2$、$1$。\n- $2$ 棵树有 $4$ 个节点:\n- 根通过颜色 $1$ 的边连接到一个子节点,该子节点再通过颜色 $2$ 的边连接到一个子节点;根还通过颜色 $2$ 的边连接到另一个子节点。\n - 根通过颜色 $2$ 的边连接到一个子节点,该子节点再通过颜色 $1$ 的边连接到一个子节点;根还通过颜色 $1$ 的边连接到另一个子节点。\n- $1$ 棵树有 $5$ 个节点:根分别通过颜色 $1$ 和颜色 $2$ 的边连接到两个子节点,并且这两个子节点各自恰好有一个颜色相反的子节点。\n\n由于 $9 \\equiv 1 \\pmod 2$,因此输出为 $1$。\n\n在第二个测试用例中,两种颜色的约束均为 $[1, 1]$。每棵有效的树都必须满足:从根出发的路径上每种颜色的边数最大值恰好为 $1$。因此,树中至少必须包含一条颜色 $1$ 的边和一条颜色 $2$ 的边。恰好存在 $6$ 棵有效的树:\n\n- $3$ 棵树有 $3$ 个节点:根分别通过颜色 $1$ 和颜色 $2$ 的边连接到两个子节点;一条颜色依次为 $1$、$2$ 的路径;一条颜色依次为 $2$、$1$ 的路径。\n- $2$ 棵树有 $4$ 个节点:与第一个测试用例中描述的两棵有 $4$ 个节点的树相同。\n- $1$ 棵树有 $5$ 个节点:与第一个测试用例中描述的有 $5$ 个节点的树相同。\n\n由于 $6 \\equiv 0 \\pmod 2$,因此输出为 $0$。"}AI (CI翻译)
样例
4
2
0 1
0 1
2
1 1
1 1
3
0 2
0 1
0 1
3
1 2
1 1
1 1
1
0
1
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。