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

Method getCentroid

src/class185/Code01_Wave1.java:230–248  ·  view source on GitHub ↗
(int u, int fa)

Source from the content-addressed store, hash-verified

228 }
229
230 public static int getCentroid(int u, int fa) {
231 // getSize1(u, fa);
232 getSize2(u, fa);
233 int half = siz[u] >> 1;
234 boolean find = false;
235 while (!find) {
236 find = true;
237 for (int e = head[u]; e > 0; e = nxt[e]) {
238 int v = to[e];
239 if (v != fa && !vis[v] && siz[v] > half) {
240 fa = u;
241 u = v;
242 find = false;
243 break;
244 }
245 }
246 }
247 return u;
248 }
249
250 public static void centroidTree(int u, int fa) {
251 centfa[u] = fa;

Callers 2

centroidTreeMethod · 0.95
mainMethod · 0.95

Calls 1

getSize2Method · 0.95

Tested by

no test coverage detected