Balanced sums in binary tree
===

I found an interesting algorithmic problem. We are given a binary tree which has value 0 in every vertex apart from leaves. In leaves we have two options:

1) value is unknown, but we know it is a natural number >=1

2) value is known and it is a natural number >=1

The problem is to decide if it is possible to set every unknown value in leaves such that every subtree of a given tree has the same sum of values in vertexes in its left and right subtree.

For example (I give vertexes preorder):

tree1:

    0
    0
    0
    ?
    NULL
    NULL
    ?
    NULL
    NULL
    5
    NULL
    NULL
    ?
    NULL
    NULL

The answer is NO - taking into consideration that every question mark has to be a natural number, it is of course not possible


tree2:

    0
    0
    0
    5
    NULL 
    NULL
    ?
    NULL
    NULL
    10
    NULL
    NULL
    0
    ?
    NULL
    NULL
    ?
    NULL
    NULL
 
the answer is YES - we set: 5, 10, 10 respectively in every question mark.


So far, I came up only with an obvious algorithm - we create system of linear equations and check if it has a solution in natural numbers. But I think it can be very slow for big trees and it should be a better way to solve it. Can anybody help? I would be very grateful.