I am learning graph algorithms and I am confused why my code 326424345 failed in test 18 for the problem https://mirror.codeforces.com/problemset/problem/977/E?
I know that the problem can be solved simply by counting the degrees of all the nodes in a connected component. Count the component when the degree of each node is 2.
However, I wanted to know what is wrong with the logic: for each connected component, we find the size of the smallest cycle, if this size equals the number of nodes in the component, count the component. (The size of the cycle initially is number of nodes + 1, so that we don't count components without cycles.
Please help me in understanding the problem, I will be very grateful to you.







