队友过的:https://blog.csdn.net/liufengwei1/article/details/101632506

Forest Program

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 124    Accepted Submission(s): 47

Problem Description
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 ≤ 300 000, 0 ≤ m ≤ 500 000), 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.
 
Sample Input
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 1
2 4
4 5
5 2
 
Sample Output
7
49
 
Source

题解:

找出所有环,每个环至少选择一条边删掉,那么方案数就是2^size-1,不在环上的边为m条,可以随便删,方案数就是2^resm。

点双抄一遍就过了,也可以直接dfs

 
参考代码:
#include<bits/stdc++.h>
#define maxl 500010
using namespace std; const int mod=; int n,m,top,cnt,ind,sum,rt,dcccnt;
vector <int> dcc[maxl];
long long ans;
int dfn[maxl],low[maxl],ehead[maxl],s[maxl];
long long num[maxl];
bool in[maxl],cut[maxl];
struct ed
{
int to,nxt;
}e[maxl<<]; inline void add(int u,int v)
{
e[++cnt].to=v;e[cnt].nxt=ehead[u];ehead[u]=cnt;
} inline void tarjan(int u)
{
dfn[u]=low[u]=++ind;s[++top]=u;
if(u==rt && ehead[u]==)
{
dcc[++dcccnt].push_back(u);
return;
}
int son=,v;
for(int i=ehead[u];i;i=e[i].nxt)
{
v=e[i].to;
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
son++;
if(u!=rt || son>)
cut[u]=true;
dcccnt++;
int d;
do
{
d=s[top--];
dcc[dcccnt].push_back(d);
}while(d!=v);
dcc[dcccnt].push_back(u);
}
}
else
low[u]=min(low[u],dfn[v]);
}
} inline void prework()
{
for(int i=;i<=dcccnt;i++)
dcc[i].clear();
dcccnt=;
for(int i=;i<=n;i++)
{
dfn[i]=low[i]=;in[i]=false;
ehead[i]=;cut[i]=false;
}
int u,v;cnt=;
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
add(u,v);add(v,u);
}
ind=;
for(int i=;i<=n;i++)
if(dfn[i]==)
{
rt=i;top=;
tarjan(i);
}
} inline void mainwork()
{
int resm=m;
ans=;
for(int i=;i<=dcccnt;i++)
{
sum=dcc[i].size();
if(sum>=)
ans=ans*num[sum]%mod,resm-=sum;
}
ans=ans*(num[resm]+)%mod;
} inline void print()
{
printf("%lld\n",ans);
} int main()
{
//freopen("1006.in","r",stdin);
num[]=;
for(int i=;i<maxl;i++)
num[i]=2ll*num[i-]%mod;
for(int i=;i<maxl;i++)
num[i]=((num[i]-)%mod+mod)%mod;
while(~scanf("%d%d",&n,&m))
{
prework();
mainwork();
print();
}
return ;
}
 
 

2019CCPC秦皇岛 F Forest Program的更多相关文章

  1. [CCPC2019秦皇岛] F. Forest Program

    [CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...

  2. Forest Program(2019ccpc秦皇岛F)

    题:http://acm.hdu.edu.cn/showproblem.php?pid=6736 题意:删掉一些边使得图不存在点双,求方案数. 分析:若一条边不属于点双,那么这条边有删和不删俩种选择, ...

  3. HDU6736 2019CCPC秦皇岛赛区 F. Forest Program

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6736思路:dfs+栈 判环           设图中环的大小分别为 c1, c2, ..., ck,不属 ...

  4. 2019ccpc秦皇岛/Gym102361 F Forest Program 仙人掌上dfs

    题意: 某地沙漠化严重,沙漠里长了很多仙人掌,现在要让你删掉仙人掌的一些边让它的所有连通分量都是树,就完成了沙漠绿化(什么鬼逻辑?)让你计算删边的方案数. 仙人掌是一种特殊的图,它的每一条边只属于1或 ...

  5. 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)

    题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...

  6. HDU - 6736 F - Forest Program

    题意 给你n个点m条边,并且保证整个图是仙人掌. 仙人掌:每条边仅属于1条或者0条回路 且无重边和自环 让你删掉一些边使其变成一棵树(拥有点数-1条边) 注意一个点也是森林 图可能是不联通的 思路 考 ...

  7. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...

  8. 2019CCPC秦皇岛赛区(重现赛)- F

    链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=872 题意: Z 国近年来一直在考虑遏制国土沙 ...

  9. 2019CCPC秦皇岛 E题 Escape(网络流)

    Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

随机推荐

  1. PHP实现微信企业付款到个人零钱步骤

    微信支付企业付款到零钱功能应用广泛,比如微信红包奖励,业务结算等.通过企业向个人付款,付款资金将直接进入用户微信零钱. 一 开通条件 ​ 付款资金 企业付款到零钱资金使用商户号余额资金. 根据商户号的 ...

  2. [LC]530题 二叉搜索树的最小绝对差

    ①题目 给定一个所有节点为非负值的二叉搜索树,求树中任意两节点的差的绝对值的最小值. 示例 : 输入: 1   \   3  / 2 输出:1 解释:最小绝对差为1,其中 2 和 1 的差的绝对值为 ...

  3. Python常用模块之os.path

    os.path.abspath(path) 输入相对路径,返回绝对路径 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1 ...

  4. linux命令指令

    1.ls显示目录内容 -a 显示目录下所有文件 -l 显示详细信息 ls *.c  列出当前目录所有的.c文件 2.uname -a  查看内核版本 3.whoami  查看谁登陆虚拟机 4.cd 切 ...

  5. 使用Charles设置https代理到http以及证书安装(服务端篇)

    1.下载ssl证书到[登录],并且设置证书[始终信任] 2.SSL Proxying设置,Location为*,可以抓全部接口的https请求 参考:https://www.jianshu.com/p ...

  6. ZeroC ICE中的对象

    在ZeroC Ice中定义了三种基本对象类型. 它们分别是IceProxy::Ice::Object(于Ice/Proxy.h),Ice::Object(于Ice/Object.h)和Ice::Loc ...

  7. 建筑行业的新起之秀---BIM

       近年来,BIM在国家在建筑行业的推进下逐渐走近人们的视线,而且BIM技术是作为建筑领域的一项新技术行业发展的越来越好,在很多的建筑场景都用到了BIM建模.施工.运维以及BIM+GIS等以BIM为 ...

  8. PostGIS 存储过程返回类型

    Postgresql存储过程返回值的方式有很多,在此先只记录一下自己用到过的,慢慢拓展 1.type型,这里geometry可以是任何postgresql支持的类型(integer/text/char ...

  9. Windows之Java开发环境快速搭建

    说明:Node.js非必须,通常中小公司或创业公司,基本上都要求全栈. 补充说明: 除此之外,当公司固定JDK.Maven.Idea.Git.Node.js及其相关IDE等版本时,运维人员或者Team ...

  10. Dubbo面试八连问,这些你都能答上来吗?

    Dubbo是什么? Dubbo能做什么? Dubbo内置了哪几种服务容器? Dubbo 核心的配置有哪些? Dubbo有哪几种集群容错方案,默认是哪种? Dubbo有哪几种负载均衡策略,默认是哪种? ...