#P17164. [CEOI 2026] DFS

    ID: 17351 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>图论树状数组CEOI(中欧)生成树2026

[CEOI 2026] DFS

题目描述

You might already be familiar with the famous DFS (depth-first search) algorithm for traversing a graph. In this problem, we will only consider connected undirected simple graphs (without loops and parallel edges) with vertices numbered 0,1,…,n−10,1,\ldots,n-1, and the DFS algorithm will output depths and vertices as follows:

DFS(d, v):
    output d/v
    mark vertex v as visited
    W = the list of neighbors of v ordered by increasing numbers
    for each w in W:
        if vertex w has not yet been visited:
            DFS(d + 1, w)

Write a program that outputs the number of different graphs for which the call DFS(00, n−1n-1) produces the same printout as the one given on the input. For example, the output

0/20/2
1/01/0
2/12/1

is produced by calling DFS(00, 22) on either of the following two connected undirected simple 33-vertex graphs:

:::align{center} :::

输入格式

The input is the output of the call DFS(00, n−1n-1) on an unknown nn-vertex connected undirected simple graph. The input thus consists of nn lines in the format d/vd/v, with the first line being 0/(n−1)0/(n-1).

输出格式

Print the number of different graphs with the required property. Because this number can be very large, output the result modulo 1 000 000 0071\,000\,000\,007.

0/2
1/0
2/1
2

提示

Constraints

  • 1≤n≤2⋅1051\le n\le 2\cdot 10^5

Subtasks

  • Subtask 11 (1010 points): n≤6n\le 6.
  • Subtask 22 (2020 points): n≤500n\le 500.
  • Subtask 33 (2020 points): n≤104n\le 10^4.
  • Subtask 44 (1010 points): For each i∈{2,…,n}i\in\{2,\ldots,n\}, the ii-th input line is (i−1)/(i−2)(i-1)/(i-2).
  • Subtask 55 (2020 points): For each i∈{2,…,n}i\in\{2,\ldots,n\}, the ii-th input line is (i−1)/v(i-1)/v for some v∈{0,…,n−2}v\in\{0,\ldots,n-2\}.
  • Subtask 66 (2020 points): No additional constraints.