| 215 | |
| 216 | // 收集信息迭代版 |
| 217 | public static void dfs2(int cur, int fa, int pcolor, int pedge, long psum) { |
| 218 | stacksize = 0; |
| 219 | push(cur, fa, pcolor, pedge, psum, -1); |
| 220 | while (stacksize > 0) { |
| 221 | pop(); |
| 222 | if (e == -1) { |
| 223 | if (edge > limitr) { |
| 224 | continue; |
| 225 | } |
| 226 | edgeCnt[u] = edge; |
| 227 | pathSum[u] = sum; |
| 228 | subtreeNode[++cnts] = u; |
| 229 | e = head[u]; |
| 230 | } else { |
| 231 | e = nxt[e]; |
| 232 | } |
| 233 | if (e != 0) { |
| 234 | push(u, f, preColor, edge, sum, e); |
| 235 | int v = to[e]; |
| 236 | int c = color[e]; |
| 237 | if (v != f && !vis[v]) { |
| 238 | push(v, u, c, edge + 1, sum + (preColor == c ? 0 : val[c]), -1); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | public static long calc(int u) { |
| 245 | cnte = 0; |