A14585 | Desert
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an undirected graph of $N$ nodes and $M$ edges, $E_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)$ , ( $1 \leq L \leq R \leq M$ ) such that, if we delete all the edges except for $E_L, E_{L+1}, \dots E_R$ , the graph is a desert.
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)$ , ( $1 \leq L \leq R \leq M$ ) such that, if we delete all the edges except for $E_L, E_{L+1}, \dots E_R$ , the graph is a desert.
输入格式
The first line contains two integers $N$ and $M$ ( $2 \leq N \leq 2.5 \times 10^5$ , $1 \leq M \leq 5 \times 10^5$ ). Each of the next $M$ lines contains two integers. The $i$ -th line describes the $i$ -th edge. It contains integers $U_i$ and $V_i$ , the nodes connected by the $i$ -th edge ( $E_i=(U_i, V_i)$ ). It is guaranteed that $1 \leq U_i, V_i \leq N$ and $U_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)$ , $(2, 2)$ and $(3, 3)$ are deserts because they don't have any cycles. Graphs for pairs $(1, 2)$ and $(2, 3)$ have one cycle of length 2 so they are deserts.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted