This is an example of an absorbing Markov chain.
Let Q[j,i] be the proportion of flow from the j^th non-sink node into the i^th non-sink node.
Let R[j,i] be the proportion of flow from the j^th non-sink node into the i^th sink node.
Then let matrix N=inv(I-Q), and matrix B=N*R.
The final amount of flow in the i^th sink node is given by B[0,i].
Python example for your first case:
import numpy as np
# Rows are proportion of flow out of each non-sink vertex
Q = np.zeros((3,3))
Q[0,:] = 0,0.3,0.7 # Flow out of S
Q[1,:] = 0,0,0 # Flow out of a
Q[2,:] = 0,0.5,0 # Flow out of b
# Rows are flow from non-sink to sink nodes
R = np.zeros((3,2))
R[1,:] = 0.1,0.9
R[2,:] = 0,0.5
N = np.matrix(np.identity(len(Q)) - Q).I
B = N*R
print B[0,:]
prints
[[ 0.065 0.935]]
Explanation
Once we have the matrices set up, we can simulate one time step of flow by starting with a row vector v containing [1,0,0] (representing the one gallon at the start) and an empty row vector e (representing the amount of water in the sinks).
In each time step we compute:
e += v * R # This works out the amount of flow that has reached the end
v = v * Q # This works out the amount of flow that is still in the network
If we simulate this for long enough we will end up with v approaching 0, and e approaching the answer.
However we can write the value for e as:
e = v*R + v*Q*R + v*Q*Q*R + v*Q*Q*Q*R +...
= v * (I + Q + Q*Q + Q*Q*Q + ...) * R
= v * inv(I-Q) * R
= v * N * R
= v * B
= [1,0,0] * B
= first row of B