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

Method dfs4

src/class185/Code01_Wave1.java:146–172  ·  view source on GitHub ↗
(int cur, int tag)

Source from the content-addressed store, hash-verified

144
145 // dfs2改成迭代版
146 public static void dfs4(int cur, int tag) {
147 stacksize = 0;
148 push(cur, 0, tag, -1);
149 while (stacksize > 0) {
150 pop();
151 if (e == -1) {
152 top[u] = t;
153 if (son[u] == 0) {
154 continue;
155 }
156 push(u, 0, t, -2);
157 push(son[u], 0, t, -1);
158 continue;
159 } else if (e == -2) {
160 e = head[u];
161 } else {
162 e = nxt[e];
163 }
164 if (e != 0) {
165 push(u, 0, t, e);
166 int v = to[e];
167 if (v != fa[u] && v != son[u]) {
168 push(v, 0, v, -1);
169 }
170 }
171 }
172 }
173
174 public static int getLca(int a, int b) {
175 while (top[a] != top[b]) {

Callers 1

mainMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected