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

Method dfs

src/class184/Code05_Freezing1.java:90–103  ·  view source on GitHub ↗
(int u, int fa, int edge, int sum, int limit)

Source from the content-addressed store, hash-verified

88 }
89
90 public static void dfs(int u, int fa, int edge, int sum, int limit) {
91 curLen = Math.max(curLen, edge);
92 if (sum > curVal[edge]) {
93 curVal[edge] = sum;
94 curNode[edge] = u;
95 }
96 for (int e = head[u]; e > 0; e = nxt[e]) {
97 int v = to[e];
98 int w = weight[e];
99 if (v != fa && !vis[v]) {
100 dfs(v, u, edge + 1, sum + (w >= limit ? 1 : -1), limit);
101 }
102 }
103 }
104
105 public static boolean check(int u, int limit) {
106 preVal[0] = 0;

Callers 1

checkMethod · 0.95

Calls 1

maxMethod · 0.45

Tested by

no test coverage detected