Consider a tree: root with children . Node has child . Paths: and .
The correct formula marks positions per path: cnt[u] += , cnt[v] += , cnt[lca(u, v)] -= , cnt[parent[lca(u, v)]] -= . The parent decrement stops the path contribution from leaking above the LCA.
Path : . Mark cnt[] += , cnt[] += , cnt[] -= , cnt[parent[]] -= .
Path : . Mark cnt[] += , cnt[] += , cnt[] -= , cnt[parent[]] -= .
After DFS propagation, each node's count reflects how many paths pass through it. Test your code to make sure the LCA adjustment is correct.