#abc284e. E - Count Simple Paths

E - Count Simple Paths

Score : 500500 points

问题描述

给定一个简单的无向图,其中包含 NN 个顶点,编号从 11NN,以及 MM 条边,编号从 11MM。第 ii 条边连接顶点 uiu_i 和顶点 viv_i。每个顶点的度数不超过 1010

KK 为从顶点 11 出发的简单路径(即不包含重复顶点的路径)的数量。输出 min(K,106)\min(K, 10^6)

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple undirected graph with NN vertices numbered 11 to NN and MM edges numbered 11 to MM. Edge ii connects vertex uiu_i and vertex viv_i. The degree of each vertex is at most 1010.
Let KK be the number of simple paths (paths without repeated vertices) starting from vertex 11. Print min(K,106)\min(K, 10^6).

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • $0 \leq M \leq \min \left(2 \times 10^5, \frac{N(N-1)}{2}\right)$
  • 1ui,viN1 \leq u_i, v_i \leq N
  • The given graph is simple.
  • The degree of each vertex in the given graph is at most 1010.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

Output

Print the answer.

Sample Input 1

4 2
1 2
2 3

Sample Output 1

3

We have the following three paths that count. (Note that a path of length 00 also counts.)

  • Vertex 11;
  • vertex 11, vertex 22;
  • vertex 11, vertex 22, vertex 33.

Sample Input 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 2

16

Sample Input 3

8 21
2 6
1 3
5 6
3 8
3 6
4 7
4 6
3 4
1 5
2 4
1 2
2 7
1 4
3 5
2 5
2 3
4 5
3 7
6 7
5 7
2 8

Sample Output 3

2023

update @ 2024/3/10 11:53:58

}