This looks like a problem of finding a Minimum Cut of a graph, requiring that minimum cut contains only 2 edges. There is for example Karger's algorithm which has complexity as
where n - number of nodes
n