2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program

题目链接

The kingdom of Z is fighting against desertification these years since there are plenty of deserts in its wide and huge territory. The deserts are too arid to have rainfall or human habitation, and the only creatures that can live inside the deserts are the cactuses. In this problem, a cactus in desert can be represented by a cactus in graph theory.

In graph theory, a cactus is a connected undirected graph with no self-loops and no multi-edges, and each edge can only be in at most one simple cycle. While a tree in graph theory is a connected undirected acyclic graph. So here comes the idea: just remove some edges in these cactuses so that the remaining connected components all become trees. After that, the deserts will become forests, which can halt desertification fundamentally.

Now given an undirected graph with n vertices and m edges satisfying that all connected components are cactuses, you should determine the number of schemes to remove edges in the graph so that the remaining connected components are all trees. Print the answer modulo 998244353.

Two schemes are considered to be different if and only if the sets of removed edges in two schemes are different.

Input

The first line contains two non-negative integers n,m (1≤n≤300000,0≤m≤500000), denoting the number of vertices and the number of edges in the given graph.

Next m lines each contains two positive integers u,v (1≤u,v≤n,u≠v), denoting that vertices u and v are connected by an undirected edge.

It is guaranteed that each connected component in input graph is a cactus.

Output

Output a single line containing a non-negative integer, denoting the answer modulo 998244353.

Examples

input

3 3
1 2
2 3
3 1

output

7

input

6 6
1 2
2 3
3 1
2 4
4 5
5 2

output

49

题意比较简单,就是删去任意数量的边使得图变成森林~
对一个长为 nnn 的环,我们可以删任意的边,答案就是 Cn1+Cn2+⋯+Cnn=2n−1C_n^1+C_n^2+\cdots +C_n^n=2^n-1Cn1​+Cn2​+⋯+Cnn​=2n−1
对于除环外的边数 kkk,我们可以任选,答案就是 2k2^k2k
题目的难点就在于求环长,我们可以在 DFS 的过程中加入深度,当出现比当前结点深度更小的结点时(不是前驱结点),那么就一定出现了环,环的长度也即深度之差,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
const ll mod=998244353;
vector<ll>G[N];
int n,m,u,v,vis[N];
ll depth[N],pow2[N],ans=1;
void init(){pow2[0]=1;for(int i=1;i<N;i++) pow2[i]=(pow2[i-1]<<1)%mod;
}void dfs(int u){vis[u]=1;for(auto v:G[u]){if(depth[v]&&depth[v]==depth[u]-1) continue;if(!depth[v]){depth[v]=depth[u]+1;dfs(v);continue;}if(depth[u]>=depth[v]){ans=ans*(pow2[depth[u]-depth[v]+1]-1)%mod;if(ans<0) ans=(mod+(-ans)%mod)%mod;m-=(depth[u]-depth[v]+1);}}
}int main(){init();scanf("%d%d",&n,&m);for(int i=0;i<m;i++){scanf("%d%d",&u,&v);G[u].push_back(v);G[v].push_back(u);}for(int i=1;i<=n;i++){if(!vis[i]){depth[i]=1;dfs(i);}}printf("%lld",ans*pow2[m]%mod);return 0;
}

2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program相关推荐

  1. 2019 China Collegiate Programming Contest Qinhuangdao K. MUV LUV UNLIMITED

    MUV LUV UNLIMITED Link 题目大意:给出一棵树,两人轮流任取(至少取一)当前树上的叶子,最先不能操作的人输. 首先考虑一个情况,若一个叶子节点 x x x 有兄弟,则先手必胜.因为 ...

  2. 2020 China Collegiate Programming Contest Qinhuangdao Site 补题部分

    已经补AEFGK E. Exam Results 枚举+二分+动态开点权值线段树O(nlogN)O(nlogN)O(nlogN) 智商太低,想不到什么贪心只能暴力数据结构维护 对于所有学生的最高成绩只 ...

  3. 【Virtual Judge】The 2019 China Collegiate Programming Contest Harbin Site-Keeping Rabbits

    Keeping Rabbits DreamGrid is the keeper of n rabbits. Initially, the i-th (1≤i≤n) rabbit has a weigh ...

  4. acm-(辗转相除法、丢番图方程)2020 China Collegiate Programming Contest Qinhuangdao Site I. Interstellar Hunter

    传送门 本题其实就是给定若干个整数向量(x1,y1),(x2,y2),...,(xn,yn)(x_1,y_1),(x_2,y_2),...,(x_n,y_n)(x1​,y1​),(x2​,y2​),. ...

  5. 2018 China Collegiate Programming Contest - Jilin Site F - The Hermit HDU - 6560 思维

    链接Problem - 6560 题意 有n个站点每个站点可以发送完美信号 关于完美信号的定义 有i j k三个站点 分别保证 i<j<k dis(i,j)> dis(j,k) 并且 ...

  6. acm -(并查集、启发式合并、gcd、枚举因子)2020 China Collegiate Programming Contest Changchun Onsite K. Ragdoll

    传送门 本题考虑直接对每个iii求出所有满足ij=gcd(i,j)i^j=gcd(i,j)ij=gcd(i,j)的jjj,然后存在ggg数组中,对于查询修改操作维护一个并查集即可,合并的时候采用启发式 ...

  7. 2016 China Collegiate Programming Contest Final

    2016 China Collegiate Programming Contest Final Table of Contents 2016 China Collegiate Programming ...

  8. 2020 China Collegiate Programming Contest Changchun F - Strange Memory(dsu on tree + 位运算小技巧)

    题目连接: https://codeforces.com/gym/102832/problem/F 首先写这个题的时候要注意内存的问题 不要瞎几把define int long long 题解: 考虑 ...

  9. 2022 China Collegiate Programming Contest (CCPC) Guilin Site - C. Array Concatenation

    C. Array Concatenation time limit per test1 second memory limit per test512 megabytes inputstandard ...

最新文章

  1. [设计模式]简单工厂模式
  2. CF809C Find a car
  3. linux下挂接fat32分区
  4. php post 获取xml,php 获取post的xml数据并解析示例
  5. anguarjs 上传图片预览_前端图片上传那些事儿
  6. 学用ASP.NET2.0
  7. 矩阵连乘问题算法思想_算法之矩阵连乘
  8. Selpg—Golang
  9. 索引是什么,如何实现?
  10. 找不到Vivado卸载程序的解决方案
  11. php header 生成pdf,使用PHP生成PDF文档
  12. python pyecharts绘制旭日图Sunburst
  13. Windows服务描述及其原理
  14. HackRF实现GPS欺骗教程
  15. Unity教程:URP渲染管线实战教程系列【1】
  16. 附上两张本人觉得不错的WIN7桌面壁纸
  17. 商学院全球化管理论坛 思科总裁林正刚作主题发言
  18. 细说linux挂载---转自ubuntu论坛 adagio
  19. 华为认证考试难吗?怎样才能通过?
  20. 写一个完整的万年历网页

热门文章

  1. 自拍会不会被大数据_这年头,不会BI软件都要被HR嫌弃了!
  2. Capture One快捷键
  3. WPF 捕获键盘输入事件
  4. STM32F0的内部RC振荡配置
  5. 代码洁癖系列(三):整洁的类和函数
  6. 学习Linux命令(25)
  7. 蓝牙音频传输格式:SBC ACC APTX LDAC
  8. CDMA 原理与计算
  9. 卫星光通信关键技术及发展态势分析
  10. Layui 弹出层选择实现