当前位置:网站首页>E - Red and Blue Graph(组合数学)
E - Red and Blue Graph(组合数学)
2022-08-01 13:22:00 【Harris-H】
E - Red and Blue Graph(组合数学)
因为要求有偶数个不同颜色的边。
记不同颜色的边个数为 x x x,颜色全为红色的边个数为 y y y。
则红色的点度数之和为: 2 y + x = s 2y+x=s 2y+x=s
即 x , s x,s x,s 奇偶性相同。
而 s s s 的奇偶性,只取决于度数为奇数的红点个数。
因此枚举红色点中度数为奇数的个数即可,剩下在度数为偶数里选。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
const ll mod=998244353;
int n,m,k,d[N],num[2];ll inv[N],fac[N],ans;
ll C(int n,int m)
{
if(n<m||m<0) return 0ll;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1,u,v;i<=m;i++)
scanf("%d %d",&u,&v),d[u]++,d[v]++;
fac[0]=inv[1]=inv[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(int i=2;i<=n;i++) inv[i]=inv[i]*inv[i-1]%mod;
for(int i=1;i<=n;i++)
num[d[i]&1]++;
for(int i=0;i<=num[1];i+=2) //度数为奇数的个数必须为偶数个
ans=(ans+C(num[1],i)*C(num[0],k-i))%mod;
printf("%lld",ans);
}
边栏推荐
猜你喜欢
随机推荐
mysql的基本使用
Towhee 每周模型
观察者模式
让程序员早点下班的效率工具
SQL function SQRT
SQL函数 %SQLSTRING
如何降低Istio服务网格中Envoy的内存开销
SQL函数 SQUARE
Detailed explanation of table join
Feign 从注册到调用原理分析
NebulaGraph v3.2.0 性能报告
台积电认清了形势,新的建厂计划没有美国,中国芯片也得到重视
How do we do full-link grayscale on the database?
如何将第三方服务中心注册集成到 Istio ?
This article will take you to thoroughly clarify the working mechanism of certificates in Isito
预防和制止家庭暴力 人身安全保护令司法解释今起施行
多线程案例——阻塞式队列
测试发文
SAP ABAP OData 服务如何支持创建(Create)操作试读版
What Can Service Mesh Learn from SDN?