QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 512 MB Points totaux : 100

#3292. 计数环

Statistiques

给定一个无向图,计算图中简单环的数量。这里,简单环是指一个连通子图,其中所有顶点的度数恰好为 2。

输入格式

输入包含单个测试用例,格式如下:

$n$ $m$ $u_1$ $v_1$ $\vdots$ $u_m$ $v_m$

测试用例表示一个无向图 $G$。

第一行包含顶点数 $n$ ($3 \le n \le 100\,000$) 和边数 $m$ ($n - 1 \le m \le n + 15$)。图中的顶点编号为 $1$ 到 $n$。

接下来的 $m$ 行指定了图的边。这 $m$ 行中的第 $i$ 行包含两个整数 $u_i$ 和 $v_i$,表示顶点 $u_i$ 和 $v_i$ 之间存在一条边。这里,可以假设 $u_i < v_i$,因此不存在自环。

对于所有 $i$ 和 $j$ ($i \neq j$),满足 $u_i \neq u_j$ 或 $v_i \neq v_j$。换句话说,不存在重边。

可以假设 $G$ 是连通的。

输出格式

输出一行,包含一个整数,即图中简单环的数量。

样例

样例输入 1

4 5
1 2
1 3
1 4
2 3
3 4

样例输出 1

3

样例输入 2

7 9
1 2
1 3
2 4
2 5
3 6
3 7
2 3
4 5
6 7

样例输出 2

3

样例输入 3

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

样例输出 3

7

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.