CF980F.Cactus to Tree
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a special connected undirected graph where each vertex belongs to at most one simple cycle.
Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles).
For each node, independently, output the maximum distance between it and a leaf in the resulting tree, assuming you were to remove the edges in a way that minimizes this distance.
你被给定一个特殊的连通无向图,其中每个顶点至多属于一个简单环。
你的任务是删除尽可能多的边,将该图转化为一棵树(即一个无环的连通图)。
对每个节点,独立地输出:在所有可能的删边方案中(这些方案均能将原图变为树),使得该节点到任意叶节点的距离最小化时,该节点到叶节点的最大距离。
输入格式
The first line of input contains two integers n and m (1≤n≤5⋅105), the number of nodes and the number of edges, respectively.
Each of the following m lines contains two integers u and v (1≤u,v≤n, u=v), and represents an edge connecting the two nodes u and v. Each pair of nodes is connected by at most one edge.
It is guaranteed that the given graph is connected and each vertex belongs to at most one simple cycle.
输入的第一行包含两个整数 n 和 m(1≤n≤5⋅105),分别表示节点数和边数。
接下来的 m 行,每行包含两个整数 u 和 v(1≤u,v≤n,u=v),表示一条连接节点 u 和 v 的边。任意两个节点之间至多有一条边。
保证给定图是连通的,且每个顶点至多属于一个简单环。
输出格式
Print n space-separated integers, the i-th integer represents the maximum distance between node i and a leaf if the removed edges were chosen in a way that minimizes this distance.
输出 n 个以空格分隔的整数,其中第 i 个整数表示:在以最小化该距离的方式选择被删除的边的前提下,节点 i 到任意叶节点的最大距离。
输入输出样例
输入#1
9 10 7 2 9 2 1 6 3 1 4 3 4 7 7 6 9 8 5 8 5 9
输出#1
5 3 5 4 5 4 3 5 4
输入#2
4 4 1 2 2 3 3 4 4 1
输出#2
2 2 2 2
说明/提示
In the first sample, a possible way to minimize the maximum distance from vertex 1 is by removing the marked edges in the following image:

Note that to minimize the answer for different nodes, you can remove different edges.
在第一个样例中,一种最小化顶点 1 到其他顶点的最大距离的方法是移除下图中所标记的边:

注意:为使不同节点的答案最小化,可以移除不同的边。
输入解题思路,AI测评打分。不知道怎么写?