Calculate max flow, you're halfway there.