xht
2020-02-10 22:04:26
设
对于给定的
对于给定的
枚举
设
考虑多元二项式定理:
原式变为:
即:
const int N = 1e5 + 7;
int n, m, k, f[N], s[N];
modint ans = 1;
int get(int x) {
return x == f[x] ? x : (f[x] = get(f[x]));
}
int main() {
rd(n), rd(m), rd(P);
if (P == 1) return print(0), 0;
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1, x, y; i <= m; i++) rd(x), rd(y), f[get(x)] = get(y);
for (int i = 1; i <= n; i++) ++s[get(i)];
for (int i = 1; i <= n; i++) if (i == get(i)) ++k, ans *= s[i];
if (k == 1) return print(1), 0;
print(ans *= (modint)n ^ (k - 2));
return 0;
}