当前位置:网站首页>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]);
}
边栏推荐
- Check password
- Xilinx Vivado set *.svh as SystemVerilog Header
- vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
- LeetCode 209. 长度最小的子数组
- taobao. trades. sold. Get query the transaction data that the seller has sold (according to the creation time), Taobao store sales order query API interface, Taobao R2 interface, Taobao oauth2.0 trans
- 数据库连接池和数据源
- 【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境
- LeetCode 2310. The number of digits is the sum of integers of K
- Uniapp automated test learning
- tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
猜你喜欢
Obsidian installs third-party plug-ins - unable to load plug-ins
buuctf-pwn write-ups (7)
Dragonfly low code security tool platform development path
About text selection in web pages and counting the length of selected text
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
解决el-radio-group 回显后不能编辑问题
C语言习题---(数组)
Makefile separates file names and suffixes
[apipost] tutorial
为什么只会编程的程序员无法成为优秀的开发者?
随机推荐
为什么只会编程的程序员无法成为优秀的开发者?
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
LeetCode 209. 长度最小的子数组
info [email protected] : The platform “win32“ is incompatible with this module.
Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
C # delay, start the timer in the thread, and obtain the system time
obsidian安装第三方插件——无法加载插件
Introduction to mathjax (web display of mathematical formulas, vector)
MFC timer usage
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
Yolov6 training: various problems encountered in training your dataset
C# richTextBox控制显示最大行数
Fatal: unsafe repository is owned by someone else
About text selection in web pages and counting the length of selected text
C语言实现N皇后问题
Database connection pool and data source
Threejs controller cube space basic controller + inertia control + flight control
Mfc a dialog calls B dialog function and passes parameters
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制