The idea is also DFS. From bottom to up, at every node, we have four choices:

the left subpath ==> node ==> the right subpath

the left subpath ==> node ==> upper. The left subpath may yield a negative sum, in which case we set node>left subpath to zero.

the right subpath ==> node ==>upper. The right subpath may yield a negative sum, in which case we set node>right subpath to zero.

0 ==> upper, which means we abandon the entire tree rooted at this node because of a negative sum.
Noted: Negative node values are possible.
class Solution
{
private:
int maxPathSum(TreeNode *root, int &ma)
{
if (!root)
return 0;
int left = maxPathSum(root>left, ma);
int right = maxPathSum(root>right, ma);
ma = max(ma, root>val + left + right);
return max(max(0, max(left, right)) + root>val, 0);
}
public:
int maxPathSum(TreeNode* root)
{
if (!root)
return INT_MIN; //This INT_MIN is just to comply with the judge.
int ma = root>val;
maxPathSum(root, ma);
return ma;
}
};