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

Method dfs3

src/class185/Code01_Wave1.java:112–143  ·  view source on GitHub ↗
(int cur, int father)

Source from the content-addressed store, hash-verified

110
111 // dfs1改成迭代版
112 public static void dfs3(int cur, int father) {
113 stacksize = 0;
114 push(cur, father, 0, -1);
115 while (stacksize > 0) {
116 pop();
117 if (e == -1) {
118 fa[u] = f;
119 dep[u] = dep[f] + 1;
120 siz[u] = 1;
121 e = head[u];
122 } else {
123 e = nxt[e];
124 }
125 if (e != 0) {
126 push(u, f, 0, e);
127 int v = to[e];
128 if (v != f) {
129 push(v, u, 0, -1);
130 }
131 } else {
132 for (int ei = head[u]; ei > 0; ei = nxt[ei]) {
133 int v = to[ei];
134 if (v != f) {
135 siz[u] += siz[v];
136 if (son[u] == 0 || siz[son[u]] < siz[v]) {
137 son[u] = v;
138 }
139 }
140 }
141 }
142 }
143 }
144
145 // dfs2改成迭代版
146 public static void dfs4(int cur, int tag) {

Callers 1

mainMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected