my solution : http://codeforces.com/contest/154/submission/31864290
approach : i first divide the graph into disjoint sets and for each set i tried to find the number of doubles. Firstly, i hav count the number of sets which contains a single element and simply add all the possible doubles into my answer (i.e ans += one*(one-1)/2) and then for each set i calculate the vertices which are connected to all other vertices in the same set and simply add total possible pairs with those vertices. Now, what i thought that if there are more pairs then their answer didn’t depend on these(vertices with all edges) vertices ! and so i just remove those vertices and their edges and thus what we have is a graph with some edges and we need to count number of doubles in it(same to original problem) so, i calculate it recursively !
one more thing, While calculating i have consider all the leaf nodes(which have only one element in it’s adjacency lists) which have a single same parent and add all possible contributions of them also (this i have done in dfs() part in my code !).
please can anyone give me some small test case where my logic lacks or the idea when my logic will fail!