Bzoj 3534 ([Sdoi2014] Reconstruction-Variable matrix-Tree theorem-Benquan product and all spanning trees)

Source: Internet
Author: User
Tags printf

The

variable-element matrix-Tree theorem, which is the Benquan of the product of all spanning trees. Change the degree to connect the Benquan and, a[i][j]=−a[i][j]=-edge right, a[i][i]= a[i][i]= to connect out of Benquan and.

#include <bits/stdc++.h> using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (I,k,n) for (int. i=k;i<=n;i++) #define FORKD (i,k,n) for (int i=n;i >=k;i--) #define REP (I,n) for (int. i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (i,n) for (int i=n;i& gt;=0;i--) #define FORP (x) for (int p=pre[x];p, p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #defin
E Lson (o<<1) #define Rson ((o<<1) +1) #define MEM (a) memset (A,0,sizeof (a));
#define MEMI (a) memset (A,0x3f,sizeof (a));
#define MEMI (a) memset (A,128,sizeof (a));
#define MEMX (A, B) memset (A,b,sizeof (a)); #define INF (0x3f3f3f3f) #define F (1000000007) #define PB push_back #define MP Make_pair #define FI first #define SE seco nd #define VI vector<int> #define PI pair<int,int> #define SI (a) ((a). Size ()) #define PR (Kcase,ans) printf ("C
ASE #%d:%lld\n ", Kcase,ans); #define PRI (A,n) for (i,n-1) cout<<a[i]<< ";
cout<<a[n]<<endl; #define PRi2D (a,n,m) for (i,n) {\ for (j,m-1) cout<<a[i][j]<< '; \ cout< <a[i][m]<<endl; \} #pragma COMMENT (linker, "/stack:102400000,102400000") #define ALL (x) (x). Begin (), (x). End () Ty
Pedef Long Long ll;
typedef long double LD;
typedef unsigned long long ull;  LL Mul (ll A,ll b) {return (a*b)%F;} ll Add (ll A,ll b) {return (a+b)%F;} ll Sub (ll A,ll b) {return ((a)%f+f)%F; void Upd (LL
    &a,ll b) {a= (a%f+b%f)%F;} inline int read () {int x=0,f=1; char Ch=getchar ();
    while (!isdigit (CH)) {if (ch== '-') f=-1; Ch=getchar ();}
    while (IsDigit (ch)) {x=x*10+ch-' 0 '; Ch=getchar ();}
return x*f;
} #define EPS (1e-8) #define MAXN (305) int n;
Double A[MAXN][MAXN];
    Double det (int n) {bool f=0;
        for (i,n) {int k=0;
        Fork (J,i,n) if (Fabs (A[j][i]) >fabs (A[k][i])) {k=j;}
        for (j,n) swap (a[i][j],a[k][j]);
        if (i^k) f^=1;
        if (Fabs (A[i][i]) <eps) continue; ForK (j,i+1,n) {double t=a[j][i]/(a[i][i]);
            Fork (k,i,n) {a[j][k]-=t*a[i][k];
    }}} double r=1;
    for (I,n) r=r*a[i][i];
    if (f) r=-r;
return R;
    } int main () {///Freopen ("Bzoj3534.in", "R", stdin);//Freopen (". Out", "w", stdout);
    int N=read ();
    MEM (a) double p=1;
        for (I,n) for (j,n) {double pp=0;
        scanf ("%lf", &pp);
        if (i^j) a[i][j]=pp;
        if (i<j) p*=1-a[i][j];
        if (i^j) a[i][j]/=1-a[i][j];
            if (i^j) {a[i][i]+=a[i][j];//A[J][J]+=A[I][J];   
        A[I][J]=-A[I][J];


    }} printf ("%.10lf\n", Det (n-1) *p);
return 0;
 }

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.