title: “子树计数模板”
date: 2024-06-03 10:42:02
updated: 2024-06-03 10:42:02
tag: [“notion”, “Algorithm”, “树与图”]
categories: “Algorithm”
mathjax: true
comments: true
description: ‘
function<int(int,int)> dfs = [&](int x, int fa) { // 当前节点x, x的父节点fa
int rt = nums[x];//当前节点值nums[x]
for (int i:g[x]) {
if (i == fa) continue;
rt += dfs(i, x);
}
return rt;
};