c++ - Finding cycles in a directed graph implemented using an unordered multimap -


so, i've implemented directed graph using unordered multimap. each pair within map made of 2 strings: vertex , adjacent vertex. now, trying determine if graph has cycle, , if so, how big cycle. code have far:

int findcycle(const unordered_multimap<string,string> & connectedurlvertices, string y, string key) {         string position;          position=y.find(key);          if(position!=string::npos)         {             return 1;         }          auto nodestocheck=connectedurlvertices.equal_range(key);          for(auto & node : nodestocheck)         {             int z=findcycle(connectedurlvertices,y+key,node);         } } 

i've walked through code on paper , seems logically correct, appreciate if take , see if on right track or missing anything. thanks!

to search cycles in graph have descend recursively through arcs initial node until reach 1 visited node (you can construct std::set of visited nodes or mark nodes visit them) or exhaust nodes without getting 1 visited (absence of cycles) criterion select arc can adjusted find more or kind of search (first in depth, search level, etc.)