当前位置:网站首页>HUSTPC2022
HUSTPC2022
2022-07-02 15:02:00 【Not Zhang Pangpang】
List of articles
H. Permutation Counting
Ideas :
Yes n ( 1 ≤ n ≤ 2 ⋅ 1 0 6 ) n(1≤n≤2⋅10^6) n(1≤n≤2⋅106) A full permutation of numbers a a a, Known n n n There is m m m A constraint x i , y i x_i,y_i xi,yi, It is known that a x i < a y i a_{xi}<a_{yi} axi<ayi, And x i x_i xi Different from each other , y i y_i yi Could be the same
Ask how many possibilities there are to satisfy all constraints ? Answer module 998244353 998244353 998244353
Ideas :
Establish a directed graph according to constraints , If there are rings in the graph , It is thought that there is no solution . conversely , Then there must be at least one understanding .
secondly , Because in the title x i x_i xi Different from each other , We can see , If the y i → x i y_i \rightarrow x_i yi→xi Even the edge , Will certainly form The forest
In order to turn the forest into a whole tree , Add extra points n + 1 n+1 n+1, Connect to the roots of all trees , So we turn the forest into a whole tree
Tree form d p dp dp, s z i sz_i szi Said to i i i Is the node size of the subtree of the tree root , f i f_i fi Express s z i sz_i szi Numbers in i i i In the subtree of the root , How many permutations are there . that
consider 10 10 10 Different stones are divided into 5 , 3 , 2 5,3,2 5,3,2 Three piles
Yes C 10 5 ⋅ C 5 3 ⋅ C 2 2 C_{10}^{5}⋅C_5^3⋅C_2^2 C105⋅C53⋅C22 Maybe
Then this question will be a size 10 10 10 The tree of nodes is divided into 4 , 3 , 2 4,3,2 4,3,2 The subtree of
Yes C 9 4 ⋅ C 5 3 ⋅ C 2 2 C_{9}^{4}⋅C_5^3⋅C_2^2 C94⋅C53⋅C22 Maybe , The largest number must be the root node .
So you only need to satisfy the root node maximum , The remaining nodes can be divided arbitrarily
/* * @Author: zhangpangpang * @Date: 2022-06-09 09:29:49 * @Last Modified by: zhangpangpang * @Last Modified time: 2022-06-09 09:29:49 */
#include<bits/stdc++.h>
#define fi first
#define gcd __gcd
#define se second
#define pb push_back
#define lowbit(x) x&-x
#define inf 0x3f3f3f3f
#define mem(x,y) memset(x,y,sizeof(x))
#define lrb666 ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int,int> PII;
const int maxn=2e6+7;
int n,m,fa[maxn],d[maxn];
ll mod=998244353,sz[maxn],f[maxn],fac[maxn],inv[maxn],finv[maxn];
ll ksm(ll b,ll p){
ll r=1;while(p>0){
if(p&1){
r=(r%mod*(b%mod))%mod;}p>>=1;b=(b%mod*(b%mod))%mod;}return r;}
void binom_init(int x) {
fac[0] = fac[1] = 1;
inv[1] = 1;
finv[0] = finv[1] = 1;
for(int i=2; i<x; i++){
fac[i] = fac[i-1]*i%mod;
inv[i] = mod-mod/i*inv[mod%i]%mod;
finv[i] = finv[i-1]*inv[i]%mod;
}
}
ll binom(ll n, ll r){
if(n<r || n<0 || r<0) return 0;
return fac[n]*finv[r]%mod*finv[n-r]%mod;
}
int find(int x)
{
if(x==fa[x])
return fa[x];
else
return fa[x]=find(fa[x]);
}
void lianjie(int x,int y)
{
int px=find(x),py=find(y);
fa[px]=py;
}
vector<int>v[maxn];
void dfs(int u,int fa)
{
sz[u]=1;f[u]=1;
ll use=0;
for(auto nx:v[u])
{
if(u==fa) continue;
dfs(nx,u);
sz[u]+=sz[nx];
}
use++;
for(auto nx:v[u])
{
if(u==fa) continue;
f[u]=(f[u]*f[nx])%mod;
f[u]=(f[u]*binom(sz[u]-use,sz[nx]))%mod;
use+=sz[nx];
}
}
int main()
{
binom_init(maxn-5);
scanf("%d%d",&n,&m);int ok=1;
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=m;i++)
{
int a,b;scanf("%d%d",&a,&b);
d[a]++;
v[b].pb(a);
if(find(a)==find(b)) ok=0;
else lianjie(a,b);
}
for(int i=1;i<=n;i++)
{
if(d[i]==0) v[n+1].pb(i);
}
if(!ok)
{
puts("0");return 0;
}
dfs(n+1,-1);
printf("%lld\n",f[n+1]);
}
边栏推荐
- Uniapp automated test learning
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- fatal: unsafe repository is owned by someone else 的解决方法
- C code audit practice + pre knowledge
- LeetCode 2320. 统计放置房子的方式数
- STM32 standard firmware library function name memory (II)
- Yolov6 training: various problems encountered in training your dataset
- jmeter脚本参数化
- Dragonfly low code security tool platform development path
- LeetCode 2320. Count the number of ways to place the house
猜你喜欢

Add vector formula in rich text editor (MathType for TinyMCE, visual addition)

socket(套接字)与socket地址
![[untitled] leetcode 2321 Maximum score of concatenated array](/img/a3/54d0e83f02ef0d0d8d269351c35b39.png)
[untitled] leetcode 2321 Maximum score of concatenated array

Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly

Makefile 分隔文件名与后缀

关于网页中的文本选择以及统计选中文本长度

为什么只会编程的程序员无法成为优秀的开发者?

STM32 library function for GPIO initialization

Large top heap, small top heap and heap sequencing

mathML转latex
随机推荐
Kityformula editor configure font size and spacing
Xilinx Vivado set *.svh as SystemVerilog Header
数据库内容输出有问题怎么解决
Ad20 cannot select the solution of component packaging in PCB editor
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
Introduction to mathjax (web display of mathematical formulas, vector)
【无标题】LeetCode 2321. 拼接数组的最大分数
LeetCode 209. Minimum length subarray
Btrace- (bytecode) dynamic tracking tool
Base64 编码原来还可以这么理解
OpenCV调用USB摄像头的点滴
C#延时、在线程中开启定时器、获取系统时间
Makefile separates file names and suffixes
STM32 standard firmware library function name (I)
华为面试题: 没有回文串
Wechat applet uses towxml to display formula
关于网页中的文本选择以及统计选中文本长度
[apipost] tutorial
【apipost】使用教程
JMeter script parameterization