From 72f5124cf4a3da281dedf332d6bca5116f8e6b49 Mon Sep 17 00:00:00 2001 From: Abdurrezzak Efe Date: Tue, 28 Nov 2017 21:33:56 +0300 Subject: [PATCH] Update 13.DFS.cpp --- 13.DFS.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) 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