diff --git a/13.DFS.cpp b/13.DFS.cpp index 4288a70..25bcd82 100644 --- a/13.DFS.cpp +++ b/13.DFS.cpp @@ -16,7 +16,7 @@ using namespace std; class Graph{ vector> edge; - vector color; // 0 black(finished node), 1 white(neither visited nor finished node) + vector color; // 1 black(finished node), 0 white(neither visited nor finished node) public: @@ -24,20 +24,21 @@ class Graph{ { edge.resize(v); color.resize(v); - for(int i=0;i st; @@ -46,12 +47,16 @@ class Graph{ while(!st.empty()) { s = st.top(); - if(color[s] == 0) - continue; - color[s] = 0, cout << s+1 << " "; st.pop(); + + if(!color[s]) + { + cout << s << " "; + color[s] = 1; + } + for(int i=0;i> u >> w, g.add_edge(u,w); + cout << endl; - for(int i=0;i