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

Method dfs4

src/class173/Code05_HLD1.java:195–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193
194 // dfs2的迭代版
195 public static void dfs4() {
196 stacksize = 0;
197 push(1, 1, -1);
198 while (stacksize > 0) {
199 pop();
200 if (edge == -1) {
201 top[first] = second;
202 dfn[first] = ++cntd;
203 val[cntd] = arr[first];
204 if (son[first] == 0) {
205 continue;
206 }
207 push(first, second, -2);
208 push(son[first], second, -1);
209 continue;
210 } else if (edge == -2) {
211 edge = head[first];
212 } else {
213 edge = next[edge];
214 }
215 if (edge != 0) {
216 push(first, second, edge);
217 if (to[edge] != fa[first] && to[edge] != son[first]) {
218 push(to[edge], to[edge], -1);
219 }
220 }
221 }
222 }
223
224 public static void query(int l, int r) {
225 if (bi[l] == bi[r]) {

Callers 1

prepareMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected