Cojs Strong connected Graph Count 1-2 report

Source: Internet
Author: User

OwO topic meaning is the same, but the data range expanded

For the n<=7 problem, we can do a direct brute force search.

For the n<=1000 problem, we can not be difficult to associate with < theme > This topic

Yes, you just have to change the equation a little.

First, we consider an illegal scheme. Strongly connected components must be a DAG after they are shrunk.

Consider child issues: Dag Count

Procedure can refer to the <cojs Dag Count 1-4 Solution Report >

This gives the transfer equation.

F (N) =sigma (( -1) ^ (k-1) *c (n,k) *2^ (k* (n-k)) *f (n-k))

What if we consider the case of a strong connected component's shrinking point?

We can define a case where g (n) indicates that n points can form several unconnected strong connected components

Consider calculating the tolerance coefficient, so if you make an odd number of strong connected components, the G (n) contribution is 1, otherwise 1

Defines the number of strongly connected graphs with n points for F (n)

Not hard to get recursive g (n) =f (n)-sigma (C (n-1,k-1) *f (k) *g (n-k))

The meaning is to consider the size of the strongly connected component of a point, the enumeration size K, then the selection scheme is C (n-1,k-1)

If the size is n, then the contribution is f (n)

Otherwise the contribution part is-g (n-k) *f (k), notice here because of a strong connected component

So the parity changes, G's positive and negative also change

Then we define h (n) to represent the number of graphs of n points, not difficult to get H (n) =2^ (n-1)

Considering the solution of F (n) by using the tolerance method, the analogy above solves the DAG and can get the following recursive

F (n) =h (n)-sigma (C (n,k) *2^ (k* (n-k)) *h (N-k) *g (k)) +f (n)

The meaning of this recursion is that a strongly connected component that enumerates some points is 0 after the indent.

Then the scheme in these points is the G (n) after the tolerance coefficient is calculated.

The selected point scheme is C (n,k), the remaining (n-k) points to the K-point arbitrary edge, the scheme is 2^ (k* (n-k))

The remaining (N-K) points are arbitrarily connected, and the scheme is H (n-k)

Notice here that the +f (n) is because when n=k, this lump is obtained by G (n), and we can only tolerate the solution of the strong connected component >1

So we get an O (n^2) recursive, can do n<=1000

For the n<=10w problem, we consider using FFT to optimize the above equation

In the above equation, F has g,g F, which is very disgusting.

Consider this equation f (n) =h (n)-sigma (C (n,k) *2^ (k* (n-k)) *h (N-k) *g (k)) +f (n)

Both sides f can be offset, we present a G (n) out and can get only about g of the recursive

g (n) =h (n)-sigma (C (n,k) *2^ (k* (n-k)) *h (N-k) *g (k)) (K-> (n-1))

about how 2^ (k* (n-k)) translates to the standard FFT form has been said in the DAG count.

namely nk=n^2/2+k^2/2-(N-K) ^2/2

And then do a cdq+fft, and we can find the G function.

then consider g (n) =f (n)-sigma (C (n-1,k-1) *f (k) *g (n-k))

Since the G function is known, we move the item to get

g (n) +sigma (C (n-1,k-1) *f (k) *g (n-k)) =f (n)

When we do a cdq+fft, we can find the F function.

Total time complexity O (nlog^2n)

Cojs Strong connected Graph Count 1-2 report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.