zoukankan      html  css  js  c++  java
  • 【BZOJ5297】【CQOI2018】社交网络(有向图生成树计数)

    传送门

    板子题+1
    套一个有向图矩阵树就完事了

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    inline int read(){
    	char ch=getchar();
    	int res=0,f=1;
    	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    	while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
    	return res*f;
    }
    const int mod=10007;
    int n,m,tr[310][310];
    int change(){
    	int ans=1,tmp=1;
    	for(int i=2;i<=n;i++){
    		for(int j=i+1;j<=n;j++){
    			int x=i,y=j;
    			while(tr[y][i]!=0){
    				int t=tr[x][i]/tr[y][i];
    				for(int k=i;k<=n;k++){
    					tr[x][k]=((tr[x][k]-tr[y][k]*t)%mod+mod)%mod;
    				}
    				swap(x,y);
    			}
    			if(x!=i){
    				for(int k=2;k<=n;k++){
    					swap(tr[i][k],tr[x][k]);
    				}
    				tmp=-tmp;
    			}
    		}
    		ans=((ans*tr[i][i])%mod+mod%mod);
    	}
    	ans=(ans*tmp%mod+mod)%mod;
    	return ans;
    }
    int main(){
    	n=read(),m=read();
    	for(int i=1;i<=m;i++){
    		int x=read(),y=read();
    		tr[x][x]++,tr[y][x]--;
    	}
    	for(int i=2;i<=n;i++){
    		for(int j=2;j<=n;j++){
    			tr[i][j]=(tr[i][j]%mod+mod)%mod;
    		}
    	}
    	cout<<change();
    }
    
  • 相关阅读:
    构建之法8,9,10章
    作业6
    通过处理器类型获得处理器对象
    面经
    C语言实现字符串替换
    计算机网络整理
    常见面试题
    数据库常见面试题
    redis常见知识整理
    项目总结
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/11145654.html
Copyright © 2011-2022 走看看