Description

Input

Output

Sample Input

样例 1 输入:
2
3 2
1 2
2 3

Sample Output

样例 1 输出:
665496241

Data Constraint


Hint

思路

树上一条路径可行的概率是1/len.(len个点,第一个点要第一个选到)
环上做一个容斥:路径A可行+路径B可行-路径AB均可行。
仙人掌上做dp容斥即可。

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353,N = 477;
int n,m;
ll fac[N],unfac[N],inv[N];
ll power(ll x,ll y)
{ll ret = 1;for(; y; y >>= 1){if (y & 1) ret = ret * x % mod;x = x * x % mod;}return ret;
}int len[N];
ll f[N][N];
int no[N],cir[N],cnt,cirbel[N];
int ls[N],nx[N * 8],to[N * 8],tot = 1;void add(int x,int y) {to[++tot] = y,nx[tot] = ls[x],ls[x] = tot;
}int dfn[N],stm,p[N],e[N * 8];
int cirfa[N],dep[N];
void dfs(int x) {dfn[x] = ++ stm;for(int i = ls[x]; i; i = nx[i]) {if (i == p[x]) continue;int y = to[i];if (dfn[y] == 0) {p[y] = i ^ 1;dep[y] = dep[x] + 1;dfs(y);} else if(dfn[y] < dfn[x]) {e[i] = e[i ^ 1] = 1;++cnt;for(int z = x,w = 1; z != y; z = to[p[z]],w++) {no[z] = w;len[z] = dep[x] - dep[y] + 1;add(z,y),add(y,z);e[p[z]] = e[p[z] ^ 1] = 1;cirfa[z] = y;cirbel[z] = cnt;}}}
}ll ans;
void work(int x,int from) {for(int i = 1; i <= n; i ++) {ans = (ans + inv[i] * f[x][i]) % mod;}for(int i = ls[x]; i; i = nx[i]) if (e[i] == 0) {int y = to[i];if (y == from) continue;if (y != cirfa[x] && cirfa[y] != x) { for(int i = 1; i <= n; i++) f[y][i] = f[x][i - 1];work(y,x);} else {int ori = 0,a = 0,b = 0,cirlen = 0;if (cirfa[x] == y) {ori = x,a = no[x],b = len[x] - no[x],cirlen = len[x];} else {if (cirbel[y] == cirbel[from]) {cirlen = len[y];ori = from,a = (no[from] - no[y] + len[y]) % cirlen,b = cirlen - a;} else {ori = x,a = no[y],b = len[y] - no[y],cirlen = len[y];}}for(int i = 1; i <= n; i++) {if (i - a > 0) f[y][i] = f[ori][i - a];if (i - b > 0) f[y][i] = (f[y][i] + f[ori][i - b]) % mod;if (i - cirlen + 1 > 0) f[y][i] = (f[y][i] - f[ori][i - cirlen + 1]) % mod;}work(y,x);}}
}int main() {freopen("falldream.in","r",stdin);freopen("falldream.out","w",stdout);cin >> n >> n >> m;for(int i = 1; i <= m; i++) {int x,y; scanf("%d %d",&x,&y);add(x,y),add(y,x);}dfs(1);fac[0] = 1;for(int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;unfac[n] = power(fac[n],mod - 2);for(int i = n - 1; ~i; i--) unfac[i] = unfac[i + 1] * (i + 1) % mod;for(int i = 1; i <= n; i++) inv[i] = unfac[i] * fac[i - 1] % mod;for(int r = 1; r <= n; r++){memset(f,0,sizeof f);f[r][1] = 1;work(r,0);}cout << (ans + mod) % mod << endl;
}

【JZOJ 省选模拟】向日葵人生相关推荐

  1. 【JZOJ 省选模拟】人生(life)

    题目 Description Input 第一行一个正整数n. 第二行n个整数,其中第i个整数为1表示点i的颜色为黑色,为0表示点i的颜色为白色,为-1 则不确定. Output 输出一行一个整数表示 ...

  2. 6687. 【JZOJ 省选模拟】树没了(tree)

    题目 Description Input Output 2操作的个数行,每行代表一个询问的答案. Sample Input 5 5 1 1 2 3 4 5 1 2 2 3 2 4 1 5 Q 1 M ...

  3. 【JZOJ 省选模拟】多项式(poly)

    题目 Description Input Output Sample Input 样例输入 1: 2 7 -7 14 样例输入 2: 3 1 4 1 5 样例输入 3: 0 998244353 Sam ...

  4. 【JZOJ 省选模拟】铺路 (road )

    题目 Description Input Output Sample Input 样例输入 1: 4 4 1 3 4 2 4 8 1 2 2 3 4 3 样例输入 2: 3 2 1 2 3 2 3 4 ...

  5. 【JZOJ 省选模拟】我的朋友们

    题目 Description Input Output 一行一个整数,表示题目描述中的期望对998244353取模的值. Sample Input 样例 1输入: 4 3 1 5 4 6 3 7 1 ...

  6. 【JZOJ 省选模拟】感受清风

    题目 Description Input Output 对于每个 qu 事件或者 qd 事件输出一个整数表示答案,答案对1000001取模(提示:这个数不 是质数,有101×9901=1000001) ...

  7. 【JZOJ 省选模拟】6681.图

    题目 Description 给定一张无重边.自环.割点的平面图,你需要回答 Q 次询问,每次询问会给出一个简单环,你需要回答在由这个简单环围成的多边形内部(包括边界上)的点有多少个. 保证图中每条线 ...

  8. 【JZOJ 省选模拟】6707.异或树(xor)

    题目 Description Input Output Sample Input 样例输入1: 2 2 998244353 样例输入2: 10 3 998244353 Sample Output 样例 ...

  9. 【JZOJ 省选模拟】迷宫(maze)

    题目 Description Input Output Sample Input 样例输入 4 8 0 A 1 B 1 A 0 B 2 A 3 B 3 A 2 B 0 C 2 D 2 C 0 D 1 ...

最新文章

  1. 2018-3-14智能算法(文章--优化问题的智能算法及其哲学内涵)笔记一(什么是优化问题)
  2. 面试再被问到 ConcurrentHashMap,把这篇文章甩给他!
  3. elementui原生属性_elementUI——主题定制
  4. ActiveMQ中Topic生产者
  5. yml配置文件中有特殊字符解决方案
  6. ckeditor的使用实例
  7. Java代码优化:使用构造函数和使用一个setter的效率差别
  8. tocmat linux搭建测试环境,Apache+Tomcat 环境搭建(JK部署过程)
  9. JS中对于prototype的理解
  10. 阿里月薪50k招AI工程师,看到要求我傻眼了!
  11. 人工智能AI系列 - 音频搜索之声纹搜索
  12. oracle地理数据库,Oracle 中的多个地理数据库 (geodatabase)
  13. STM32 DCMI调试
  14. 《Kotlin从零到精通Android开发》面世啦
  15. 让Python程序自动玩数独游戏,秒变最强大脑!
  16. EasyPusher手机直播推送是如何实现后台直播推送的
  17. vue判断有没有滚动条
  18. 异常(Exception)
  19. mysql in 分组,基于mysql实现group by取各分组最新一条数据
  20. 行人重识别多个数据集格式统一为market1501格式

热门文章

  1. 物流行业响起一声春雷,未来所有的购物或都能朝订夕达?
  2. leetcode1018
  3. 使用DirectInput进行交互(2)
  4. Power2Go 13中文版
  5. 2022化工自动化控制仪表考试试题及答案
  6. 通过云速搭CADT实现云原生分布式数据库PolarDB-X 2.0的部署
  7. 苹果计算机软件安装打不开,iPad2安装的软件怎么打不开
  8. 常见车规级芯片汇总 ---高通820A、高通8155P、高通8195 和 特斯拉HW3.0芯片
  9. mysql对标准sql的扩展_mysql对标准sql的goup by进行了扩展
  10. 新书推荐——华为·无线局域网应用技术(微课版丨第2版)