2
$\begingroup$

Let's consider the cluster as a non-empty set of edges that can be divided into one or more cycles so that exactly one cycle went along each edge of the chosen set. Besides, each cycle can consist only of edges from the chosen set. Cluster doesn't have to be connected.

We keep on adding edges in our graph, and as we add edge we count the number of ways of forming a cluster.

The solution to this problem is that let ans be 1 initially. Now as we add an edge between u and v, and if they are in same component then multiply ans by 2. Final answer after adding an edge would be (ans-1).

Why is this correct?
Problem Link
Explanation that is not clear to me.

  • 0
    Welcome to the site. It is generally best to include all relevant information in the question itself, in case links die. I recommend you do that.2017-01-21
  • 0
    Programming questions are too big and what they require can be described in smaller sentences. Anyway, the links will not die as the site is well trusted and a successful programming site.2017-01-21

0 Answers 0