1. 程式人生 > >[CQOI 2018]社交網絡

[CQOI 2018]社交網絡

tps std blog %d ble CP ret ext HP

Description

題庫鏈接

\(n\) 個點以 \(1\) 為根的有向生成樹個數。

\(1\leq n\leq 250\)

Solution

我終於會 \(\texttt{Matrix-Tree}\) 辣!!

寫詳解是不可能的,直接丟鏈接。

註意的是有向圖度數矩陣是入度。

Code

#include <bits/stdc++.h>
using namespace std;
const int N = 250+5, yzh = 10007;

int n, m, u, v, a[N][N];

int gauss() {
    int ans = 1;
    for (int i = 2
; i <= n; i++) { for (int j = i+1; j <= n; j++) while (a[j][i]) { int t = a[i][i]/a[j][i]; for (int k = i; k <= n; k++) (a[i][k] -= a[j][k]*t%yzh) %= yzh; swap(a[i], a[j]); ans *= -1; } (ans *= a[i][i]) %= yzh; } return
(ans+yzh)%yzh; } void work() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &v, &u); ++a[v][v], --a[u][v]; } printf("%d\n", gauss()); } int main() {work(); return 0; }

[CQOI 2018]社交網絡