【BZOJ3659】Which Dreamed It【有向图欧拉回路计数】【matrix tree定理】【BEST定理】【高斯消元】
来源:互联网 发布:会计办公软件用友 编辑:程序博客网 时间:2024/06/10 16:39
【题目链接】
定理题...
/* Think Thank Thunk */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 105, p = 1000003;int n, fact[200005], A[maxn][maxn], du[maxn];inline int iread() {int f = 1, x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';return f * x;}inline int qpow(int a, int n) {int res = 1;for(; n; n >>= 1, a = (LL)a * a % p) if(n & 1) res = (LL)res * a % p;return res;}inline int gauss() {for(int i = 1; i < n; i++) {if(!A[i][i]) for(int j = i + 1; j < n; j++) if(A[j][i]) {for(int k = i; k < n; k++) swap(A[i][k], A[j][k]);break;}int rev = qpow(A[i][i], p - 2);for(int j = i + 1; j < n; j++) if(A[j][i]) {int t = (LL)A[j][i] * rev % p;for(int k = i; k < n; k++) A[j][k] = (A[j][k] - (LL)A[i][k] * t % p + p) % p;}}int res = 1;for(int i = 1; i < n; i++) res = (LL)res * A[i][i] % p;return res;}int main() {fact[0] = 1;for(int i = 1; i <= 200000; i++) fact[i] = (LL)fact[i - 1] * i % p;while(1) {n = iread();if(!n) break;for(int i = 1; i <= n; i++) {du[i] = 0;for(int j = 1; j <= n; j++) A[i][j] = 0;}for(int i = 1; i <= n; i++) {du[i] = iread();for(int j = 1; j <= du[i]; j++) {int x = iread();if(x != i) A[i][x]--, A[i][i]++;}}if(n == 1 && du[1] == 0) {printf("1\n");continue;}for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++)(A[i][j] += p) %= p;int ans = (LL)gauss() * du[1] % p;for(int i = 1; i <= n; i++) ans = (LL)ans * fact[du[i] - 1] % p;printf("%d\n", ans);}return 0;}
0 0
- 【BZOJ3659】Which Dreamed It【有向图欧拉回路计数】【matrix tree定理】【BEST定理】【高斯消元】
- 【BZOJ3659】Which Dreamed It
- BZOJ3659: Which Dreamed It
- [BEST定理 矩阵树定理] BZOJ 3659 Which Dreamed It
- CSU 1805 Tree Capitals(Matrix-Tree定理+Best定理)
- hdu6064 Best theorem+Matrix-Tree定理
- 生成树的计数Matrix-Tree定理
- 生成树计数-Matrix-Tree定理
- 生成树计数-Matrix-Tree定理
- 生成树的计数Matrix-Tree定理
- 生成树计数(Matrix-Tree定理)
- 生成树计数 - Matrix Tree定理
- 生成树的计数Matrix-Tree定理
- 生成树计数--矩阵树定理(Matrix-Tree定理)
- BZOJ 3659: Which Dreamed It 基尔霍夫矩阵 best theorem
- Matrix-Tree定理
- UVA10766(Organising the Organisation)生成树计数-Matrix-Tree定理
- 最小生成树计数(Kruskal+Matrix-Tree定理)
- 史上最通俗易懂的Android中使用Dagger入门教程
- Android 讯飞语音合成
- Design Support Library介绍
- 导出导出redis里面的key值
- turtlebot2不能与kobuki连接
- 【BZOJ3659】Which Dreamed It【有向图欧拉回路计数】【matrix tree定理】【BEST定理】【高斯消元】
- linux 编译 安装 thrift
- javax.servlet.ServletRequest.getAttribute(String name)与getParameter(String name)的使用
- 通过浏览器的URL获取参数
- 复制构造函数和赋值运算符根本的不同
- Constructor常用方法
- 【转载】功能测试时需要注意的点
- Android 系统添加第三方apk到data/app
- 【精】Linux磁盘I/O性能监控之iostat详解