ARC062F AtCoDeerくんとグラフ色塗り / Painting Graphs with AtCoDeer Burnside 引理

题目传送门

https://atcoder.jp/contests/arc062/tasks/arc062_d

题解

首先对整张图做 Tarjan 点双。

对于一个点双,如果是由一条边构成的,那么很显然就是 \(K\) 种方案。

如果是由一个单环构成,可以直接使用 Burnside 引理,假设这个环的长度为 \(l\),则这个单环的贡献就是 \(\frac{\sum \limits_{i=0}^{l-1} k^{\gcd(i, l)}}l\)

否则,这个点双就是一个复合环。经过一些手动模拟的尝试,我们可以大胆地猜想对于复合环中的任意两个边的颜色都可以互换。实际上,对于两个环的情况,我们都可以通过讲转两个小环和转外面的大环相结合的方法实现。证明不详细展开。

这样的话,对于两个复合环,只要里面每一种颜色的数量都对应相同,就是同构的。于是这个就转化成了相同的小球放进不同的盒子的问题,直接插板法解决。贡献为 \(\binom{l+k-1}{k-1}\)

将每一个点双的贡献相乘即可。


下面是代码。Tarjan 寻找点双的复杂度为 \(O(n+m)\),计算贡献的过程中需要用到排序、计算 \(\gcd\) 和快速幂等操作,因此总的时间复杂度为 \(O((n+m)\log m)\)

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b , 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I>
inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 50 + 7;
const int M = 100 + 7;
const int P = 1e9 + 7;

int n, m, k, ans, tp, dfc;
int inv[M << 1], fac[M << 1], ifac[M << 1], pw[M << 1];
int dfn[N], low[N], s[M], hh[M], ss[M << 1];

struct Edge { int to, ne; } g[M << 1]; int head[N], tot = 1;
inline void addedge(int x, int y) { g[++tot].to = y, g[tot].ne = head[x], head[x] = tot; }
inline void adde(int x, int y) { addedge(x, y), addedge(y, x); }

inline int smod(int x) { return x >= P ? x - P : x; }
inline void sadd(int &x, int y) { x += y; x >= P ? x -= P : x; }
inline int fpow(int x, int y) {
	int ans = 1;
	for (; y; y >>= 1, x = (ll)x * x % P) if (y & 1) ans = (ll)ans * x % P;
	return ans;
}

inline void ycl(const int &n) {
	fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i]  = (ll)fac[i - 1] * i % P;
	inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = (ll)(P - P / i) * inv[P % i] % P;
	ifac[0] = 1; for (int i = 1; i <= n; ++i) ifac[i] = (ll)ifac[i - 1] * inv[i] % P;
	pw[0] = 1; for (int i = 1; i <= n; ++i) pw[i] = (ll)pw[i - 1] * k % P;
}
inline int C(int x, int y) {
	if (x < y) return 0;
	return (ll)fac[x] * ifac[y] % P * ifac[x - y] % P;
}

inline void dfs(int x, int fa = 0) {
	dfn[x] = low[x] = ++dfc;
	for fec(i, x, y) if (y != fa) {
		if (!dfn[y]) {
			s[++tp] = i >> 1;
			dfs(y, x);
			smin(low[x], low[y]);
			if (low[y] >= dfn[x]) {
				hh[0] = 0;
				while (1) {
					int z = s[tp--];
					hh[++hh[0]] = z;
//					dbg("%d\n", z);
					if (z == i >> 1) break;
				}
//				dbg("\n");
				if (hh[0] == 1) { ans = (ll)ans * k % P; /*dbg("type: 1\n\n"); */continue;}
				ss[0]  = 0;
				for (int i = 1; i <= hh[0]; ++i) ss[++ss[0]] = g[hh[i] << 1].to, ss[++ss[0]] = g[hh[i] << 1 | 1].to;
				std::sort(ss + 1, ss + ss[0] + 1);
				ss[0] = std::unique(ss + 1, ss + ss[0] + 1) - ss - 1;
				if (ss[0] != hh[0]) { ans = (ll)ans * C(hh[0] + k - 1, k - 1) % P; /*dbg("type: 2\n\n"); */continue;}
				int cnt = 0;
				for (int i = 0; i < hh[0]; ++i) sadd(cnt, pw[std::__gcd(i, hh[0])]);
//				dbg("cnt = %d\n", cnt);
				ans = (ll)ans * cnt % P * inv[hh[0]] % P;
//				dbg("type: 3\n\n");
			}
		} else smin(low[x], dfn[y]), dfn[y] < dfn[x] ? s[++tp] = i >> 1 : 0;
	}
}

inline void tarjan() {
	for (int i = 1; i <= n; ++i)
		if (!dfn[i]) dfs(i);
}

inline void work() {
	ycl(m + k);
	ans = 1;
	tarjan();
	printf("%d\n", ans);
}

inline void init() {
	read(n), read(m), read(k);
	for (int i = 1; i <= m; ++i) {
		int x, y;
		read(x), read(y);
		adde(x, y);
	}
}

int main() {
	#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
	#endif
	init();
	work();
	fclose(stdin), fclose(stdout);
	return 0;
}
posted @ 2019-09-07 15:59  hankeke303  阅读(294)  评论(0编辑  收藏  举报