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

Method getSize2

src/class183/Code03_Race1.java:90–116  ·  view source on GitHub ↗
(int cur, int fa)

Source from the content-addressed store, hash-verified

88
89 // 得到子树大小迭代版
90 public static void getSize2(int cur, int fa) {
91 stacksize = 0;
92 push(cur, fa, 0, 0, -1);
93 while (stacksize > 0) {
94 pop();
95 if (e == -1) {
96 siz[u] = 1;
97 e = head[u];
98 } else {
99 e = nxt[e];
100 }
101 if (e != 0) {
102 push(u, f, 0, 0, e);
103 int v = to[e];
104 if (v != f && !vis[v]) {
105 push(v, u, 0, 0, -1);
106 }
107 } else {
108 for (int ei = head[u]; ei > 0; ei = nxt[ei]) {
109 int v = to[ei];
110 if (v != f && !vis[v]) {
111 siz[u] += siz[v];
112 }
113 }
114 }
115 }
116 }
117
118 public static int getCentroid(int u, int fa) {
119 // getSize1(u, fa);

Callers 1

getCentroidMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected