Builds graph for max flow