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

Method getSize2

src/class185/Code02_Game1.java:150–176  ·  view source on GitHub ↗
(int cur, int fa)

Source from the content-addressed store, hash-verified

148
149 // getSize1的迭代版
150 public static void getSize2(int cur, int fa) {
151 stacksize = 0;
152 push(cur, fa, -1);
153 while (stacksize > 0) {
154 pop();
155 if (e == -1) {
156 siz[u] = 1;
157 e = head[u];
158 } else {
159 e = nxt[e];
160 }
161 if (e != 0) {
162 push(u, f, e);
163 int v = to[e];
164 if (v != f && !vis[v]) {
165 push(v, u, -1);
166 }
167 } else {
168 for (int ei = head[u]; ei > 0; ei = nxt[ei]) {
169 int v = to[ei];
170 if (v != f && !vis[v]) {
171 siz[u] += siz[v];
172 }
173 }
174 }
175 }
176 }
177
178 public static int getCentroid(int u, int fa) {
179 // getSize1(u, fa);

Callers 1

getCentroidMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected