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

Method getCentroid

src/class185/Code02_Game1.java:178–196  ·  view source on GitHub ↗
(int u, int fa)

Source from the content-addressed store, hash-verified

176 }
177
178 public static int getCentroid(int u, int fa) {
179 // getSize1(u, fa);
180 getSize2(u, fa);
181 int half = siz[u] >> 1;
182 boolean find = false;
183 while (!find) {
184 find = true;
185 for (int e = head[u]; e > 0; e = nxt[e]) {
186 int v = to[e];
187 if (v != fa && !vis[v] && siz[v] > half) {
188 fa = u;
189 u = v;
190 find = false;
191 break;
192 }
193 }
194 }
195 return u;
196 }
197
198 public static void centroidTree(int u, int fa) {
199 centfa[u] = fa;

Callers 2

centroidTreeMethod · 0.95
mainMethod · 0.95

Calls 1

getSize2Method · 0.95

Tested by

no test coverage detected