• P4455 [CQOI2018]社交网络(矩阵树定理)


    题目

    P4455 [CQOI2018]社交网络

    (CQOI)的题都这么裸的吗??

    做法

    有向图,指向叶子方向 (D^{out}(G)-A(G))

    至于证明嘛,反正也就四个定理,先挖个坑,省选后再来补

    My complete code

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<ctime>
    using namespace std;
    typedef int LL;
    const int p=10007;
    const int maxn=300;
    inline LL Read(){
    	LL x(0),f(1); char c=getchar();
    	while(c<'0'||c>'9'){
    		if(c=='-') f=-1; c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	    x=(x<<3)+(x<<1)+c-'0',c=getchar();
    	return x*f;
    }
    LL n,m;
    LL D[maxn][maxn];
    inline LL Pow(LL base,LL b){
    	LL ret(1);
    	while(b){
    		if(b&1)
    		    ret=ret*base%p;
    		base=base*base%p,
    		b>>=1;
    	}return ret;
    }
    inline LL Solve(){
    	LL N(n),tr(0),ans(1);
    	for(LL i=2;i<=N;++i){
    		LL mx(i);
    		for(LL j=i+1;j<=N;++j)
    		    if(D[mx][i]<D[j][i])
    		        mx=j;
    		if(D[mx][i]==0)
    		    return 0;
    		if(mx!=i){
    			swap(D[mx],D[i]),
    			tr^=1;
    		}
    		for(LL j=i+1;j<=N;++j){
    			LL tmp=D[j][i]*Pow(D[i][i],p-2)%p;
    			for(LL k=1;k<=N;++k)
    			    D[j][k]=(D[j][k]-tmp*D[i][k]%p+p)%p;
    		}
    		ans=ans*D[i][i]%p;
    	}
    	if(tr)
    	    ans=p-ans;
    	return ans;
    }
    int main(){
    	n=Read(),m=Read();
    	while(m--){
    		LL v(Read()),u(Read());
    		++D[v][v],D[u][v]=(D[u][v]+p-1)%p;
    	}
    	printf("%d
    ",Solve());
    	return 0;
    }/*
    */
    
  • 相关阅读:
    POJ 2513 (Trie树+欧拉通路+并查集判断连通)
    归并排序及序列逆序数
    POJ 2442 Sequence (堆+K路归并)
    POJ 2513 (Trie树+欧拉通路+并查集判断连通)
    J2EE概述
    J2EE概述
    J2EE概述
    学习视频资料下载论坛
    J2EE概述
    J2EE概述
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/10266260.html
Copyright © 2020-2023  润新知