简体   繁体   中英

The longest cycle in an undirected graph

How i can get the longest cycle in a undirected Graph (without BackTracking, it takes too long).

Example:

0 3 0 1 0
3 0 0 1 0
0 0 0 0 0
1 1 0 0 0
0 0 0 0 0

Solve: 3 + 3 + 1 => Out: 1 - 2 - 3 - 1.

If you can find the longest cycle, you can detect whether the graph has a Hamiltonian Cycle, which is an NP-complete problem, thus making your problem NP-hard.

That means no solution will be fundamentally better than backtracking unless P=NP.

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