Cycles on graphs

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
Alessandro
New poster
Posts: 27
Joined: Mon Jun 14, 2004 10:33 pm
Location: Latina, Italy

Cycles on graphs

Post by Alessandro »

I propose you a problem about cycles on graphs.

Given an undirected unweighted graph and two nodes A and B, I've got to find a path from A to B and then a path from B to A. I can't visit a node more than once (with the exception of node A, that must be visited at the beginning and at the end). I have to determine the maximum number of nodes that can be visited with such paths.

In other words, I have to find a cycle that contains A and B and touches the maximum number of nodes.

Any hint? :)

Ciao
Alessandro
Alessandro Piva, Member of the Italian Team at the International Olimpiad in Informatics 2004
Email: alex.ander@infinito.it
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

You can reduce Hamiltonian cycle to this. (Is there a cycle in which max = N?)

Therefore, it's NP-complete.
Alessandro
New poster
Posts: 27
Joined: Mon Jun 14, 2004 10:33 pm
Location: Latina, Italy

Post by Alessandro »

Oh, yes... For my high school final exam I presented a work about NP-completeness, and now I remember Hamiltonian cycle is NP-complete of course!

F**k (the problem, not you Larry :) )
Alessandro Piva, Member of the Italian Team at the International Olimpiad in Informatics 2004
Email: alex.ander@infinito.it
Post Reply

Return to “Algorithms”