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

Method getSize2

src/class184/Code03_Courier1.java:80–106  ·  view source on GitHub ↗
(int cur, int fa)

Source from the content-addressed store, hash-verified

78
79 // 得到子树大小迭代版
80 public static void getSize2(int cur, int fa) {
81 stacksize = 0;
82 push(cur, fa, 0, 0, -1);
83 while (stacksize > 0) {
84 pop();
85 if (e == -1) {
86 siz[u] = 1;
87 e = head[u];
88 } else {
89 e = nxt[e];
90 }
91 if (e != 0) {
92 push(u, f, 0, 0, e);
93 int v = to[e];
94 if (v != f && !vis[v]) {
95 push(v, u, 0, 0, -1);
96 }
97 } else {
98 for (int ei = head[u]; ei > 0; ei = nxt[ei]) {
99 int v = to[ei];
100 if (v != f && !vis[v]) {
101 siz[u] += siz[v];
102 }
103 }
104 }
105 }
106 }
107
108 public static int getCentroid(int u, int fa) {
109 // getSize1(u, fa);

Callers 1

getCentroidMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected