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

Method dfs3

src/class185/Code04_Fantasy1.java:113–146  ·  view source on GitHub ↗
(int cur, int father, int distance)

Source from the content-addressed store, hash-verified

111 }
112
113 public static void dfs3(int cur, int father, int distance) {
114 stacksize = 0;
115 push(cur, father, distance, 0, -1);
116 while (stacksize > 0) {
117 pop();
118 if (e == -1) {
119 fa[u] = f;
120 dep[u] = dep[f] + 1;
121 dist[u] = a;
122 siz[u] = 1;
123 e = head[u];
124 } else {
125 e = nxt[e];
126 }
127 if (e != 0) {
128 push(u, f, a, 0, e);
129 int v = to[e];
130 int w = weight[e];
131 if (v != f) {
132 push(v, u, a + w, 0, -1);
133 }
134 } else {
135 for (int ei = head[u]; ei > 0; ei = nxt[ei]) {
136 int v = to[ei];
137 if (v != f) {
138 siz[u] += siz[v];
139 if (son[u] == 0 || siz[son[u]] < siz[v]) {
140 son[u] = v;
141 }
142 }
143 }
144 }
145 }
146 }
147
148 public static void dfs4(int cur, int tag) {
149 stacksize = 0;

Callers 1

mainMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected