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

Method getSize2

src/class185/Code06_ChengDu1.java:136–162  ·  view source on GitHub ↗
(int cur, int fa)

Source from the content-addressed store, hash-verified

134
135 // getSize1的迭代版
136 public static void getSize2(int cur, int fa) {
137 stacksize = 0;
138 push(cur, fa, 0, 0, -1);
139 while (stacksize > 0) {
140 pop();
141 if (e == -1) {
142 siz[u] = 1;
143 e = headg[u];
144 } else {
145 e = nxtg[e];
146 }
147 if (e != 0) {
148 push(u, f, 0, 0, e);
149 int v = tog[e];
150 if (v != f && !vis[v]) {
151 push(v, u, 0, 0, -1);
152 }
153 } else {
154 for (int ei = headg[u]; ei > 0; ei = nxtg[ei]) {
155 int v = tog[ei];
156 if (v != f && !vis[v]) {
157 siz[u] += siz[v];
158 }
159 }
160 }
161 }
162 }
163
164 public static int getCentroid(int u, int fa) {
165 // getSize1(u, fa);

Callers 1

getCentroidMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected