If You’re looking for a complete answer, then just check other answers – there are tons of questions regarding used algorithms and I’ve also found an answer with code ported to many different programming languages (Cpp version is also there)
Algorithm explanation
C++ version
I’d strongly recommend though, that You take a look at algorithms and implement them here, without removing already written code. It’s much better to write it yourself, then just copy-past – You’ll learn a lot more 😉
If You need any more precise help, write Your current status & we’ll see.
2
solved Find the Shortest Cycle in Graph