logo AlgoBeat OnlineJudge
登录 注册

#217409. [CEOI 2026] DFS

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 , 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(, ) produces the same printout as the one given on the input. For example, the output



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

:::align{center} :::

输入格式

The input is the output of the call DFS(, ) on an unknown -vertex connected undirected simple graph. The input thus consists of lines in the format , with the first line being .

输出格式

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

样例

样例输入 1

0/2
1/0
2/1

样例输出 1

2

数据范围与提示

Constraints

Subtasks

  • Subtask ( points): .
  • Subtask ( points): .
  • Subtask ( points): .
  • Subtask ( points): For each , the -th input line is .
  • Subtask ( points): For each , the -th input line is for some .
  • Subtask ( points): No additional constraints.