@dis_rain It visited every node and every edge once, so should be O(V+E)
@zhugejunwei Why don't we directly build hashset<UndirectedGraphNode> set instead of hashMap and add myNode in the set each time?
I made a mistake like you said....
wonderful!!!! without recursive, we can use queue, however performance has declined!
@loick Thank you for the clear explanation
No one has replied
@tongzhou2 the author clearly did not put into the stack all neighbors. The proposed "DFS iteratively" one is a standard stack-based DFS solution.
@ericakimnh It looks like BSF, but he's actually popping from the end of the list, not the head, which makes it DFS. At first I thought it BSF too :)
I figure it out : marks[n->label] is the copy of n, they are not the same address.
It's exactly a DFS copy, and comparing with BFS version, it looks concise.
Here are my BFS copy.
this should be corrected. It is confusing people.
Well, now the paragraph about OJ's undirected graph serialization is not useful at all to solve this question.
@ArchiiiTech I agree. This problem itself is actually a directed graph. All edges in the graph are unidirectional.
@lijinglun, visited[x->label] = x; // i think this step is not necessary
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.