A9335 | New Year Cactus
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Jack and Jill are tired of the New Year tree, now they've got a New Year cactus at home! A cactus is a connected undirected graph where any two simple cycles have at most one common vertex. In other words, this graph doesn't have any edges that lie on more than one simple cycle.
On the 31st of December they are going to decorate the cactus by hanging toys to its vertices. At most one toy is going to hang on each vertex — it's either the toy Jack hung or the toy Jill hung. It's possible for a vertex to have no toys.
Jack and Jill has been arguing, so they don't want any edge to connect two vertices where one vertex has Jack's toy and the other vertex has Jill's toy.
Jack has decided to hang $a$ toys. What maximum number of toys $b$ can Jill hang if they both cooperate to maximize this value? Your task is to write a program that finds the sought $b$ for all $a$ from 0 to the number of vertices on the New Year Cactus.
On the 31st of December they are going to decorate the cactus by hanging toys to its vertices. At most one toy is going to hang on each vertex — it's either the toy Jack hung or the toy Jill hung. It's possible for a vertex to have no toys.
Jack and Jill has been arguing, so they don't want any edge to connect two vertices where one vertex has Jack's toy and the other vertex has Jill's toy.
Jack has decided to hang $a$ toys. What maximum number of toys $b$ can Jill hang if they both cooperate to maximize this value? Your task is to write a program that finds the sought $b$ for all $a$ from 0 to the number of vertices on the New Year Cactus.
输入格式
The first line contains two integers $n$ and $m$ ( $1<=n<=2500,n-1<=m$ ) — the number of vertices and the number of edges, correspondingly. The next $m$ lines contain two integers $a$ , $b$ each ( $1<=a,b<=n,a≠b$ ) that mean that there is an edge connecting vertices $a$ и $b$ . Any pair of vertices has at most one edge between them.
输出格式
The first line must contain space-separated $b_{a}$ (for all $0<=a<=n$ ) where $b_{a}$ equals the maximum number of Jill's toys on the cactus considering that it has $a$ Jack's toys. Numbers $b_{a}$ go in the order of increasing $a$ .
输入输出样例
输入 #1
1 0
输出 #1
1 0
输入 #2
16 20 1 2 3 4 5 6 6 7 7 8 9 10 10 11 11 12 13 14 15 16 1 5 9 13 14 10 10 6 6 2 15 11 11 7 7 3 16 12 8 4
输出 #2
16 13 12 12 10 8 8 7 6 4 4 3 3 1 0 0 0
The cactus from the second example is:


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted