Arc062-f. Painting Graphs with Atcodeer (polya+ point dual-link component)

Source: Internet
Author: User

Tag: char is \ n type graphs har pac getc display

Seems to have not written a blog for a long time .... Hurry up and make up an article

    • Test instructions: give you a \ (n\) Point, no heavy edge and self-loop diagram.
      There \ (m\) edge, each side can dye \ (1 \to k\) in a color.
      For any simple ring, the color of its edges can be rotated any bit.
      Ask for the number of different staining schemes in nature.

    • Data range:
      \ (1\le n \le 50\\ 1 \le m \le 100\\1 \le k \le 100\\\)

    • Exercises

Divide the edges into 3 types:

    1. Does not belong to any one simple ring, its contribution is \ (k\) .
    2. belongs to and belongs to only one simple ring, with a ring length of \ (n\) . Its contribution is
      \[\displaystyle \frac{1}{n} \sum_{i=0}^{n-1} k^{\gcd (i, N)}\]
      This is similar to the necklace dyeing scheme number solution, for reasons see this blog post.

    3. belong to multiple rings. The ability to prove that the color of any two edges can be exchanged by rotation.
      So the essence is different when and only if there is a different number of colors,
      Its contribution is to use the partition method to divide the \ (m\) edge into the (k\) Group scheme number (each group does not have to have edges)
      So we're going to add a lot of \ (k-1\) partitions, and then the contribution is
      \[{n + k-1 \choose k-1}\]

This can all use \ (tarjan\) to find the double-link component (the method of cutting point) to determine the type, and in which to calculate.
The complexity of time is \ (O (n+m) \) easy to pass this question.

    • Code:
#include <bits/stdc++.h>#define FOR (I, L, R) for (int i = (l), i# #end = (int) (r), I <= i# #end; ++i)#define Fordown (i, R, L) for (int i = (r), i# #end = (int) (l); I >= i# #end; i.)#define SET (A, V) memset (A, V, sizeof (a))using namespaceStdBOOLChkmin (int&a,intb) {returnb < A? A = B,1:0;}BOOLChkmax (int&a,intb) {returnB > A? A = B,1:0;}inline intRead () {intx =0, FH =1;Charch = getchar (); for(;!isdigit (ch); ch = getchar ())if(ch = ='-') FH =-1; for(; isdigit (ch); ch = getchar ()) x = (x <<1) + (x <<3) + (ch ^' 0 ');returnx * FH;}voidFile () {#ifdef Zjp_shadowFreopen ("F.in","R", stdin); Freopen ("F.out","W", stdout);#endif}Const intN = -, M =205;typedef Long LongllConstll Mod =1e9+7; ll FPM (ll X,intPower) {LL res =1; for(; power; power >>=1, (x *= x)%= Mod)if(Power &1) (res *= x)%= Mod;returnRes;} ll Fac[m], ifac[m];voidInit (intMAXN) {fac[0] = ifac[0] =1ll; for (I,1, MAXN) Fac[i] = fac[i-1] * I% Mod; IFAC[MAXN] = FPM (FAC[MAXN), Mod-2); Fordown (i, MAXN-1,1) Ifac[i] = Ifac[i +1] * (i +1)% Mod;} ll C (intMintN) {if(M > N | | n <0|| M <0)return 0LL;returnFAC[N] * ifac[m]% mod * ifac[n-m]% MoD;} Set <int> point;intN, M, K; ll ans =1ll; ll Polya (intN) {ll res =0; for (I,1, n) (res = FPM (k, __GCD (n, i)))%= Mod;returnRes * FPM (n, Mod-2)% Mod;} ll Permu (intm) {returnC (K-1, M + K-1); }vector<int> G[n];intDfn[n], Lowlink[n], sta[n], top;voidTarjan (intUintFA) {Static intCLK =0; Dfn[u] = Lowlink[u] = (+ + CLK); sta[++ top] = u; for(intV:g[u])if(!dfn[v]) {Tarjan (V, u), Chkmin (Lowlink[u], lowlink[v]);if(Lowlink[v] >= Dfn[u]) {point.clear ();intn =0, M =0, last; DoPoint.insert (last = sta[top--]), + + N; while(Last! = v); Point.insert (U), + + N; for(intX:point) for(intV:G[X])if((BOOL) Point.count (v)) + + M; M >>=1;if(M < n) (ans *= k)%= Mod;if(M = = N) (Ans *= Polya (n))%= Mod;if(M > N)        (Ans *= Permu (m))%= Mod; }    }ElseChkmin (Lowlink[u], dfn[v]);if(!FA)-top;}intMain () {File (); n = Read (), M = Read ();    K = read (); Init (m + k +5); for (I,1, m) {intU = Read (), V = read ();        G[u].push_back (v);    G[v].push_back (U); } for (I,1, N)if(!dfn[i]) Tarjan (I,0); printf ("%lld\n", ans);return 0;}

Arc062-f. Painting Graphs with Atcodeer (polya+ point dual-link component)

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.