i) There is a an edge (a,b) such that P(u,a) is true and P(b,v) is true.

]]>iii) The label of u and the label of v sum to zero, and there is an edge (u,v).

]]>Define P(u,v) to be the predicate “there is a valid path from u to v”. Then P(u,u) is false for all u.

And, isn’t it the following claim true?

Claim: for u != v, P(u,v) is true if and only if one of the following two conditions holds?

i) There is a vertex w such that P(u,w) is true and P(w,v) is true.

ii) The label of u and the label of v sum to zero, and there are edges (u,a) and (b,w) such that P(a,b) is true.

If indeed thisÂ claim holds, it gives you a dynamic programming algorithm running in time, say, O(N^4). You can probably improve that.

]]>