简体   繁体   中英

How do i detect a cycle in a undirected graph and drop the edge with the maximum weight in that cycle?

I know DFS or union-find can be used to detect a cycle. But is there a quick way to find the edge with the maximum weight in that cycle?

No, DFS and sequential search is the optimal solution. Just find the cycle and go through its edges to find the maximum weight edge. The complexity doesn't really matter here - you had to find the cycle anyway and the complexity of finding the maximum edge is the same.

没有一个好的方法只能执行一次,但是如果要迭代直到图形非循环,则将留下最小的生成树,该树可以在线性运算时间内进行计算。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM