[ABC262E] Red and Blue Graph

Problem Statement

You are given a simple undirected graph with $N$ vertices and $M$ edges. The vertices are numbered $1, \dots, N$, and the $i$-th $(1 \leq i \leq M)$ edge connects Vertices $U_i$ and $V_i$.

There are $2^N$ ways to paint each vertex red or blue. Find the number, modulo $998244353$, of such ways that satisfy all of the following conditions:

  • There are exactly $K$ vertices painted red.
  • There is an even number of edges connecting vertices painted in different colors.

Constraints

  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq M \leq 2 \times 10^5$
  • $0 \leq K \leq N$
  • $1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)$
  • $(U_i, V_i) \neq (U_j, V_j) \, (i \neq j)$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$ $K$
$U_1$ $V_1$
$\vdots$
$U_M$ $V_M$

Output

Print the answer.


Sample Input 1

4 4 2
1 2
1 3
2 3
3 4
选出来的 $k$ 个红色点点的度数之和一定是偶数。如果一条边链接两个红色点,那么他会被算两次。如果他链接一个红色点和一个蓝色点,那么按要求,这种边有奇数个。 换句话说,我们只能选择偶数个奇数度数的店。枚举选 $i$ 个奇数度数的点,设有 $c0$ 个偶数度数的点,$c1$ 个奇数度数的店,那么答案加上 $C_{c0}^{k-i}\times C_{c1}^i$
#include<cstdio>
const int N=2e5+5,P=998244353;
int n,m,k,in[N],jc[N],c1,c0,u,v,ans;
int pow(int x,int y)
{
	if(!y)
		return 1;
	int t=pow(x,y>>1);
	if(y&1)
		return 1LL*t*t%P*x%P;
	return 1LL*t*t%P;
//	return (y&1)? 1LL*t*t%P*x%P:1LL*t*t%P;
}
int calc(int x,int y)
{
	if(x<y)
		return 0;
	return 1LL*jc[x]*pow(jc[y],P-2)%P*pow(jc[x-y],P-2)%P;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=jc[0]=1;i<=n;i++)
		jc[i]=1LL*jc[i-1]*i%P;
//	printf("%d\n",pow(2,10)%P);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		in[u]++,in[v]++;
	}
	for(int i=1;i<=n;i++)
		in[i]&1? c1++:c0++;
//	printf("%d %d\n",c1,c0);
	for(int i=0;i<=k;i+=2)//选多少个奇数的
	{
//		printf("%d %d %d\n",i,calc(c1,i),calc(c0,k-i));
		ans+=1LL*calc(c1,i)*calc(c0,k-i)%P;
		ans%=P;
	}
	printf("%d",ans);
}
posted @ 2022-09-08 22:11  灰鲭鲨  阅读(26)  评论(0编辑  收藏  举报