CF2239F.Colorful Works

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gold14526 is a painter. He can paint with nn colors, numbered 1,2,…,n1, 2, \ldots, n. Color ii has a constraint interval [li,ri][l_i, r_i].

A work is defined as a rooted tree T=(V,E)T=(V,E) where every edge is colored (with one of the nn colors). A work is called colorful if the following conditions are satisfied:

  • For any three nodes u,v,w∈Vu, v, w \in V, if edges (u,v)(u,v) and (v,w)(v,w) both exist, they must have different colors.
  • For all colors i∈[1,n]i \in [1,n], let d(u,i)d(u,i) denote the number of edges of color ii on the simple path from node uu to the root. Then max⁡u∈Vd(u,i)∈[li,ri]\max_{u \in V} d(u,i) \in [l_i, r_i].

Two works T=(V,E)T=(V,E) and T′=(V′,E′)T'=(V',E') are defined as isomorphic if and only if the following two conditions are met:

  • ∣V∣=∣V′∣\lvert V\rvert = \lvert V'\rvert;
  • There exists a bijection f:V→V′f:V \to V' such that:
    • Let rr be the root of TT and r′r' be the root of T′T'. Then f(r)=r′f(r) = r';
    • For any (u,v)∈E(u,v) \in E, we have that (f(u),f(v))∈E′(f(u),f(v)) \in E', and the color of edge (u,v)(u,v) is the same as the color of edge (f(u),f(v))(f(u),f(v)).

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 2\bf2.

Gold14526 是一位画家。他可用 nn 种颜色进行绘画,颜色编号为 1,2,…,n1, 2, \ldots, n。颜色 ii 具有约束区间 [li,ri][l_i, r_i]。

一幅作品定义为一棵有根树 T=(V,E)T=(V,E),其中每条边均被染色(使用 nn 种颜色之一)。若一幅作品满足以下条件,则称其为多彩的(colorful):

  • 对任意三个节点 u,v,w∈Vu, v, w \in V,若边 (u,v)(u,v) 和 (v,w)(v,w) 均存在,则它们的颜色必须不同;
  • 对所有颜色 i∈[1,n]i \in [1,n],令 d(u,i)d(u,i) 表示从节点 uu 到根节点的简单路径上颜色为 ii 的边的数量,则需满足 max⁡u∈Vd(u,i)∈[li,ri]\max_{u \in V} d(u,i) \in [l_i, r_i]。

两幅作品 T=(V,E)T=(V,E) 与 T′=(V′,E′)T'=(V',E') 被定义为同构的(isomorphic),当且仅当满足以下两个条件:

  • ∣V∣=∣V′∣\lvert V\rvert = \lvert V'\rvert;
  • 存在双射 f:V→V′f:V \to V',使得:
    • 设 rr 为 TT 的根节点,r′r' 为 T′T' 的根节点,则 f(r)=r′f(r) = r';
    • 对任意 (u,v)∈E(u,v) \in E,均有 (f(u),f(v))∈E′(f(u),f(v)) \in E',且边 (u,v)(u,v) 的颜色与边 (f(u),f(v))(f(u),f(v)) 的颜色相同。

Gold14526 想知道:他最多能选出多少幅互不同构的多彩作品?输出答案对 2\bf2 取模的结果。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1061\le n\le 2\cdot 10^6) — denoting the number of colors.

The following nn lines each contain two integers, the ii -th of them lil_i and rir_i (0≤li≤ri≤2⋅1050\le l_i\le r_i\le 2\cdot 10^5, ri≥1r_i\ge 1) — denoting the constraint interval of the ii -th color.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1062\cdot 10^6.

Let m=max⁡i=1nrim=\max_{i=1}^n r_i. Then it is guaranteed that the sum of mm over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1061\le n\le 2\cdot 10^6),表示颜色种类数。

接下来的 nn 行,每行包含两个整数;其中第 ii 行为 lil_i 和 rir_i(0≤li≤ri≤2⋅1050\le l_i\le r_i\le 2\cdot 10^5,且 ri≥1r_i\ge 1),表示第 ii 种颜色的约束区间。

保证所有测试用例中 nn 的总和不超过 2⋅1062\cdot 10^6。

令 m=max⁡i=1nrim=\max_{i=1}^n r_i,则保证所有测试用例中 mm 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, output 00 or 11, representing the maximum number of works that can be chosen modulo 22.

对于每个测试用例,输出 00 或 11,表示最多可选择的作品数量对 22 取模的结果。

输入输出样例

  • 输入#1

    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

    1
    0
    1
    1

说明/提示

In the first test case, the constraints for both colors are [0,1][0, 1]. This means on any simple path from the root, there can be at most 11 edge of color 11 and at most 11 edge of color 22. There are exactly 99 valid pairwise non-isomorphic trees:

  • 11 tree with 11 node: just the root.
  • 22 trees with 22 nodes: the root is connected to a child by an edge of color 11, or by an edge of color 22.
  • 33 trees with 33 nodes:
    • the root is connected to two children by edges of color 11 and 22 respectively.
    • a path of 22 edges from the root, colored 11 then 22.
    • a path of 22 edges from the root, colored 22 then 11.
  • 22 trees with 44 nodes:
    • the root has a child via color 11 (which further has a child via color 22), and another child via color 22.
    • the root has a child via color 22 (which further has a child via color 11), and another child via color 11.
  • 11 tree with 55 nodes: the root is connected to two children by colors 11 and 22, and each of these children has exactly one child of the opposite color.

Since 9≡1(mod2)9 \equiv 1 \pmod 2, the output is 11.

In the second test case, the constraints for both colors are [1,1][1, 1]. Every valid tree must satisfy the maximum count of each color on the paths to be exactly 11. Therefore, the tree must contain at least one edge of color 11 and at least one edge of color 22. There are exactly 66 valid trees:

  • 33 trees with 33 nodes: the root connected to two children by colors 11 and 22; a path colored 11 then 22; a path colored 22 then 11.
  • 22 trees with 44 nodes: same as the two 44-node trees described in the first test case.
  • 11 tree with 55 nodes: same as the 55-node tree described in the first test case.

Since 6≡0(mod2)6 \equiv 0 \pmod 2, the output is 00.

在第一个测试用例中,两种颜色的约束均为 [0,1][0, 1]。这意味着:在从根节点出发的任意简单路径上,颜色 11 的边至多出现 11 次,颜色 22 的边也至多出现 11 次。恰好存在 99 棵互不同构的有效树:

  • 11 棵含 11 个节点的树:仅包含根节点。
  • 22 棵含 22 个节点的树:根节点通过颜色 11 的边连接一个子节点,或通过颜色 22 的边连接一个子节点。
  • 33 棵含 33 个节点的树:
    • 根节点分别通过颜色 11 和颜色 22 的边连接两个子节点;
    • 从根节点出发的长度为 22 的路径,其边颜色依次为 11、22;
    • 从根节点出发的长度为 22 的路径,其边颜色依次为 22、11。
  • 22 棵含 44 个节点的树:
    • 根节点通过颜色 11 的边连接一个子节点(该子节点再通过颜色 22 的边连接其子节点),同时根节点还通过颜色 22 的边连接另一个子节点;
    • 根节点通过颜色 22 的边连接一个子节点(该子节点再通过颜色 11 的边连接其子节点),同时根节点还通过颜色 11 的边连接另一个子节点。
  • 11 棵含 55 个节点的树:根节点通过颜色 11 和颜色 22 的边分别连接两个子节点,且这两个子节点各自恰好有一个颜色与父边相反的子节点。

由于 9≡1(mod2)9 \equiv 1 \pmod 2,输出为 11。

在第二个测试用例中,两种颜色的约束均为 [1,1][1, 1]。每棵有效树必须满足:从根节点出发的任意路径上,每种颜色的边出现次数恰好为 11。因此,该树必须至少包含一条颜色 11 的边和一条颜色 22 的边。恰好存在 66 棵有效树:

  • 33 棵含 33 个节点的树:根节点通过颜色 11 和颜色 22 的边连接两个子节点;颜色序列为 11、22 的长度为 22 的路径;颜色序列为 22、11 的长度为 22 的路径。
  • 22 棵含 44 个节点的树:与第一个测试用例中描述的两棵 44 节点树相同。
  • 11 棵含 55 个节点的树:与第一个测试用例中描述的 55 节点树相同。

由于 6≡0(mod2)6 \equiv 0 \pmod 2,输出为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页