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

Method getSize2

src/class184/Code01_Capital1.java:98–124  ·  view source on GitHub ↗
(int cur, int fa)

Source from the content-addressed store, hash-verified

96
97 // 得到子树大小迭代版
98 public static void getSize2(int cur, int fa) {
99 stacksize = 0;
100 push(cur, fa, 0, -1);
101 while (stacksize > 0) {
102 pop();
103 if (e == -1) {
104 siz[u] = 1;
105 e = headg[u];
106 } else {
107 e = nextg[e];
108 }
109 if (e != 0) {
110 push(u, f, 0, e);
111 int v = tog[e];
112 if (v != f && !vis[v]) {
113 push(v, u, 0, -1);
114 }
115 } else {
116 for (int ei = headg[u]; ei > 0; ei = nextg[ei]) {
117 int v = tog[ei];
118 if (v != f && !vis[v]) {
119 siz[u] += siz[v];
120 }
121 }
122 }
123 }
124 }
125
126 public static int getCentroid(int u, int fa) {
127 // getSize1(u, fa);

Callers 1

getCentroidMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected