51stDimension's blog

By 51stDimension, history, 5 years ago, In English

Problem Link

According to the Editoral

The answer is supposed to be

Let K be = Number of components such the number of edges == number of vertices then the answer is pow(2,k)

I used the same method but I calculated the number of cycles in each connected component. Le var be a variable. And if the cyclecount in a connected component is == 1 then I do var++ and later on the ans = pow(2,var)

I am getting 6 WA.

My Code

There is a possibility that my cycleCount function is wrong. If thats the case please do let me know!

Thank you!

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In circle graph your code prints 0 but it should be 2

»
5 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

The issue is that your logic has a very little flaw.

Suppose a graph has 2 connected components. One component has a cycle, while another component has 0 cycles. Answer should be 0 in that case (because there is no way to direct edges of the second component), while your logic would still say 2.

EDIT: Try this test case: 7 6 1 2 2 3 3 4 5 6 6 7 5 7