A9887 | Vitaly and Cycle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After Vitaly was expelled from the university, he became interested in the graph theory.
Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.
Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of $n$ vertices and $m$ edges, not necessarily connected, without parallel edges and loops. You need to find $t$ — the minimum number of edges that must be added to the given graph in order to form a simple cycle of an odd length, consisting of more than one vertex. Moreover, he must find $w$ — the number of ways to add $t$ edges in order to form a cycle of an odd length (consisting of more than one vertex). It is prohibited to add loops or parallel edges.
Two ways to add edges to the graph are considered equal if they have the same sets of added edges.
Since Vitaly does not study at the university, he asked you to help him with this task.
Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.
Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of $n$ vertices and $m$ edges, not necessarily connected, without parallel edges and loops. You need to find $t$ — the minimum number of edges that must be added to the given graph in order to form a simple cycle of an odd length, consisting of more than one vertex. Moreover, he must find $w$ — the number of ways to add $t$ edges in order to form a cycle of an odd length (consisting of more than one vertex). It is prohibited to add loops or parallel edges.
Two ways to add edges to the graph are considered equal if they have the same sets of added edges.
Since Vitaly does not study at the university, he asked you to help him with this task.
输入格式
The first line of the input contains two integers $n$ and $m$ ( — the number of vertices in the graph and the number of edges in the graph.
Next $m$ lines contain the descriptions of the edges of the graph, one edge per line. Each edge is given by a pair of integers $a_{i}$ , $b_{i}$ ( $1<=a_{i},b_{i}<=n$ ) — the vertices that are connected by the $i$ -th edge. All numbers in the lines are separated by a single space.
It is guaranteed that the given graph doesn't contain any loops and parallel edges. The graph isn't necessarily connected.
Next $m$ lines contain the descriptions of the edges of the graph, one edge per line. Each edge is given by a pair of integers $a_{i}$ , $b_{i}$ ( $1<=a_{i},b_{i}<=n$ ) — the vertices that are connected by the $i$ -th edge. All numbers in the lines are separated by a single space.
It is guaranteed that the given graph doesn't contain any loops and parallel edges. The graph isn't necessarily connected.
输出格式
Print in the first line of the output two space-separated integers $t$ and $w$ — the minimum number of edges that should be added to the graph to form a simple cycle of an odd length consisting of more than one vertex where each vertex occurs at most once, and the number of ways to do this.
输入输出样例
输入 #1
4 4 1 2 1 3 4 2 4 3
输出 #1
1 2
输入 #2
3 3 1 2 2 3 3 1
输出 #2
0 1
输入 #3
3 0
输出 #3
3 1
The simple cycle is a cycle that doesn't contain any vertex twice.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted