MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / dfs2

Method dfs2

src/class122/Code01_MaxFlow2.java:130–154  ·  view source on GitHub ↗
(int root)

Source from the content-addressed store, hash-verified

128 // dfs2方法的递归版改迭代版
129 // 不会改,看讲解118,讲了怎么从递归版改成迭代版
130 public static void dfs2(int root) {
131 stackSize = 0;
132 push(root, 0, -1);
133 while (stackSize > 0) {
134 pop();
135 if (e == -1) {
136 e = head[u];
137 } else {
138 e = next[e];
139 }
140 if (e != 0) {
141 push(u, f, e);
142 if (to[e] != f) {
143 push(to[e], u, -1);
144 }
145 } else {
146 for (int e = head[u], v; e != 0; e = next[e]) {
147 v = to[e];
148 if (v != f) {
149 num[u] += num[v];
150 }
151 }
152 }
153 }
154 }
155
156 public static void main(String[] args) throws IOException {
157 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Callers 1

mainMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected