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

Method dfs

src/class180/Code04_WorldTree1.java:86–101  ·  view source on GitHub ↗
(int u, int fa)

Source from the content-addressed store, hash-verified

84 }
85
86 public static void dfs(int u, int fa) {
87 dep[u] = dep[fa] + 1;
88 siz[u] = 1;
89 dfn[u] = ++cntd;
90 stjump[u][0] = fa;
91 for (int p = 1; p < MAXP; p++) {
92 stjump[u][p] = stjump[stjump[u][p - 1]][p - 1];
93 }
94 for (int e = headg[u]; e > 0; e = nextg[e]) {
95 int v = tog[e];
96 if (v != fa) {
97 dfs(v, u);
98 siz[u] += siz[v];
99 }
100 }
101 }
102
103 public static int getLca(int a, int b) {
104 if (dep[a] < dep[b]) {

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected