CF1599I.Desert

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an undirected graph of NN nodes and MM edges, E1,E2,…EME_1, E_2, \dots E_M.

A connected graph is a cactus if each of it's edges belogs to at most one simple cycle. A graph is a desert if each of it's connected components is a cactus.

Find the number of pairs (L,R)(L, R), (1≤L≤R≤M1 \leq L \leq R \leq M) such that, if we delete all the edges except for EL,EL+1,…ERE_L, E_{L+1}, \dots E_R, the graph is a desert.

给你一个包含 NN 个节点和 MM 条边 E1,E2,…,EME_1, E_2, \dots, E_M 的无向图。

若一个连通图的每条边至多属于一个简单环,则该图称为仙人掌图(cactus)。若一个图的每个连通分量均为仙人掌图,则该图称为沙漠图(desert)。

请你计算满足如下条件的数对 (L,R)(L, R)(其中 1≤L≤R≤M1 \leq L \leq R \leq M)的个数:仅保留边集 {EL,EL+1,…,ER}\{E_L, E_{L+1}, \dots, E_R\},所得到的图是一个沙漠图。

输入格式

The first line contains two integers NN and MM (2≤N≤2.5×1052 \leq N \leq 2.5 \times 10^5, 1≤M≤5×1051 \leq M \leq 5 \times 10^5). Each of the next MM lines contains two integers. The ii-th line describes the ii-th edge. It contains integers UiU_i and ViV_i, the nodes connected by the ii-th edge (Ei=(Ui,Vi)E_i=(U_i, V_i)). It is guaranteed that 1≤Ui,Vi≤N1 \leq U_i, V_i \leq N and Ui≠ViU_i \neq V_i.

第一行包含两个整数 NN 和 MM(2≤N≤2.5×1052 \leq N \leq 2.5 \times 10^5,1≤M≤5×1051 \leq M \leq 5 \times 10^5)。接下来的 MM 行每行包含两个整数。第 ii 行描述第 ii 条边,包含整数 UiU_i 和 ViV_i,表示第 ii 条边所连接的两个节点(即 Ei=(Ui,Vi)E_i=(U_i, V_i))。保证 1≤Ui,Vi≤N1 \leq U_i, V_i \leq N 且 Ui≠ViU_i \neq V_i。

输出格式

The output contains one integer number – the answer.

输出包含一个整数——答案。

输入输出样例

  • 输入#1

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

    输出#1

    20
  • 输入#2

    2 3
    1 2
    1 2
    1 2

    输出#2

    5

说明/提示

In the second example: Graphs for pairs (1,1)(1, 1), (2,2)(2, 2) and (3,3)(3, 3) are deserts because they don't have any cycles. Graphs for pairs (1,2)(1, 2) and (2,3)(2, 3) have one cycle of length 2 so they are deserts.

在第二个例子中:对 (1,1)(1, 1)、(2,2)(2, 2) 和 (3,3)(3, 3) 的图是荒漠图,因为它们不含任何环;对 (1,2)(1, 2) 和 (2,3)(2, 3) 的图各含一个长度为 22 的环,因此它们也是荒漠图。

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

首页