传送门

有向图生成树计数 (度数 ->入度->外向树)

BEST定理 (不定起点的欧拉回路个数=某点为根的外向树个数(存在欧拉回路->每个点为根的外向树个数相等)*(每个点的度数(存在欧拉回路->每个点入度=出度)-1)的阶层)

一个题解的传送门

  1 //Achen
  2 #include<algorithm>
  3 #include<iostream>
  4 #include<cstring>
  5 #include<cstdlib>
  6 #include<vector>
  7 #include<cstdio>
  8 #include<queue>
  9 #include<cmath>
 10 #include<set>
 11 #include<map>
 12 #define Formylove return 0
 13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
 14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
 15 const int N=505,p=998244353;
 16 typedef long long LL;
 17 typedef double db;
 18 using namespace std;
 19 LL n,d[N][N],fac[8000007],in[N],out[N];
 20
 21 template<typename T>void read(T &x)  {
 22     char ch=getchar(); x=0; T f=1;
 23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
 24     if(ch=='-') f=-1,ch=getchar();
 25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
 26 }
 27
 28 LL a[N][N];
 29 LL gauss(int n) {
 30     For(i,1,n) For(j,1,n) (a[i][j]+=p)%=p;
 31     LL rs=1,f=1;
 32     For(i,1,n) {
 33         For(j,i+1,n) {
 34             LL A=a[i][i],B=a[j][i];
 35             while(B) {
 36                 LL t=A/B; A%=B; swap(A,B);
 37                 For(k,i,n) a[i][k]=(a[i][k]-t*a[j][k]%p+p)%p;
 38                 For(k,i,n) swap(a[i][k],a[j][k]); f=-f;
 39             }
 40         }
 41         rs=rs*a[i][i]%p;
 42     }
 43     if(f==-1) rs=(p-rs)%p;
 44     return rs;
 45 }
 46
 47 LL ksm(LL a,LL b) {
 48     LL rs=1,bs=a%p;
 49     while(b) {
 50         if(b&1) rs=rs*bs%p;
 51         bs=bs*bs%p;
 52         b>>=1;
 53     }
 54     return rs;
 55 }
 56
 57 int main() {
 58 #ifdef ANS
 59     freopen(".in","r",stdin);
 60     freopen(".out","w",stdout);
 61 #endif
 62     fac[0]=1; int cas=0;
 63     For(i,1,1000000) fac[i]=fac[i-1]*i%p;
 64     while(~scanf("%lld",&n)) {
 65         cas++;
 66         For(i,1,n) in[i]=out[i]=0;
 67         For(i,1,n) For(j,1,n) a[i][j]=0;
 68         For(i,1,n) For(j,1,n) {
 69             read(d[i][j]);
 70             a[i][j]-=d[i][j];
 71             a[j][j]+=d[i][j];
 72             (out[i]+=d[i][j])%=p;
 73             (in[j]+=d[i][j])%=p;
 74         }
 75         int fl=0;
 76         For(i,1,n) if(in[i]!=out[i]) {
 77             fl=1; break;
 78         }
 79         if(fl) {
 80             printf("Case #%d: 0\n", cas);
 81             continue;
 82         }
 83         For(i,2,n) For(j,2,n) a[i-1][j-1]=a[i][j];
 84         LL ans=gauss(n-1);
 85         For(i,2,n)
 86             ans=ans*fac[in[i]-1]%p;
 87         ans=ans*fac[in[1]]%p;
 88         For(i,1,n) For(j,1,n) if(d[i][j])
 89             ans=ans*ksm(fac[d[i][j]],p-2)%p;
 90         printf("Case #%d: %lld\n",cas,ans);
 91     }
 92     Formylove;
 93 }
 94 /*
 95 5
 96 0 1 0 0 0
 97 0 0 1 0 4
 98 0 0 0 5 0
 99 1 5 0 0 0
100 0 0 0 1 0
101 */

View Code

转载于:https://www.cnblogs.com/Achenchen/p/9499687.html

HDU 6064 RXD and numbers相关推荐

  1. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  2. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)...

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

  3. [HDU]-6060 RXD and dividing

    URL : http://acm.hdu.edu.cn/showproblem.php?pid=6060 RXD has a tree T, with the size of n. Each edge ...

  4. HDU 6061 RXD and functions(NTT)

    RXD and functions 首先是有一个结论,对多项式做任意多次 transformation ,其结果跟做一次 transformation Tr(f,∑i=1mai)Tr(f, \sum\ ...

  5. (HDU)1058 --Humble Numbers( 丑数)

    题目链接:http://vjudge.net/problem/HDU-1058 这题有点难度,自己写了半天依旧TLE,参考了其他人的博客. http://blog.csdn.net/pythonfx/ ...

  6. 基尔霍夫定理 Kirchhoff's Matrix-Tree Theorem

    推荐博客: 基尔霍夫定理 直观应用: 给定一个无向图/有向图G,求它生成树的个数t(G) 可以运用高斯消元求矩阵行列式(高斯消元法有待学习) 例题: HDU 6064 RXD and numbers ...

  7. 杭电OJ分类题目(2)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...

  8. HDU 5676 ztr loves lucky numbers

    -亚信科技,巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州)  (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队?  ztr loves lucky numbers Time Li ...

  9. HDU 1492 The number of divisors(约数) about Humble Numbers(数论,简单约数)

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

最新文章

  1. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
  2. 基于Apache Flink的爱奇艺实时计算平台建设实践
  3. vMware vSphere 5.0发布时间
  4. 15000个开源项目中挑选Top 12
  5. AjaxPost、冒泡示例
  6. 更新pcb封装导入_PCB设计│网表导入的雷区,你还在踩?
  7. tomcat启动成功 未加载项目_新里程|尚品食品国际贸易合伙人项目成功启动
  8. 两轮差速机器人坐标系及运动轨迹描述
  9. python入门指南全文阅读-Python-3.4-入门指南(官方中文版).pdf
  10. HTML基础——HTML
  11. pdf合并成一个pdf软件下载?pdf合并成一个pdf软件合成器工具
  12. 网页在线播放器 ····
  13. MFC TeeChart 用法整理二
  14. 英文名大全及含义(男)
  15. VS2017各版本区别
  16. ppt插入html(用office而不是wps)
  17. 学硕与专硕 计算机,2019计算机考研选学硕还是专硕?
  18. 小米手机夜间模式在哪设置?仅需2个步骤
  19. BOM:04-BOM有哪些形式?(按用途划分)
  20. C++程序设计基础之(第三章)函数

热门文章

  1. 【51单片机快速入门指南】2.1:数码管显示数字、小数 (科学计数法)
  2. 【机器视觉学习笔记】Harris 角点检测算法(C++)
  3. C++ 高级篇(五)—— 预处理指令
  4. Find和FirstOrDefault()有什么区别?
  5. [react] 在React中组件和元素有什么区别?
  6. React开发(129):ant design学习指南之form中的layout
  7. react(90)--时间戳比较
  8. 前端学习(2985):一文理解数据劫持3观察者模式
  9. [css] 使用纯css能否监控到用户的一些信息?怎么实现?
  10. [js] alert如何让文本换行?