2019CCPC秦皇岛 F Forest Program
队友过的: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
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.
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.
1 2
2 3
3 1
6 6
1 2
2 3
3 1
2 4
4 5
5 2
49
题解:
找出所有环,每个环至少选择一条边删掉,那么方案数就是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的更多相关文章
- [CCPC2019秦皇岛] F. Forest Program
[CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...
- Forest Program(2019ccpc秦皇岛F)
题:http://acm.hdu.edu.cn/showproblem.php?pid=6736 题意:删掉一些边使得图不存在点双,求方案数. 分析:若一条边不属于点双,那么这条边有删和不删俩种选择, ...
- HDU6736 2019CCPC秦皇岛赛区 F. Forest Program
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6736思路:dfs+栈 判环 设图中环的大小分别为 c1, c2, ..., ck,不属 ...
- 2019ccpc秦皇岛/Gym102361 F Forest Program 仙人掌上dfs
题意: 某地沙漠化严重,沙漠里长了很多仙人掌,现在要让你删掉仙人掌的一些边让它的所有连通分量都是树,就完成了沙漠绿化(什么鬼逻辑?)让你计算删边的方案数. 仙人掌是一种特殊的图,它的每一条边只属于1或 ...
- 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)
题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...
- HDU - 6736 F - Forest Program
题意 给你n个点m条边,并且保证整个图是仙人掌. 仙人掌:每条边仅属于1条或者0条回路 且无重边和自环 让你删掉一些边使其变成一棵树(拥有点数-1条边) 注意一个点也是森林 图可能是不联通的 思路 考 ...
- 2019-ccpc秦皇岛现场赛
https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...
- 2019CCPC秦皇岛赛区(重现赛)- F
链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=872 题意: Z 国近年来一直在考虑遏制国土沙 ...
- 2019CCPC秦皇岛 E题 Escape(网络流)
Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
随机推荐
- centos6的redis安装
1.到redis的官网下载redis压缩包 https://redis.io/ 2.利用命令 mkdir /usr/local/redis 新建redis文件夹 并将redis压缩包移动到新建的文件夹 ...
- Unity中用Mesh画一个圆环
Probuider 前几天在做一个小项目的时候,用到了Unity自带的一个包ProBuilder其中的Arch生成1/4圆. 挺好玩的,可以在直接Unity中根据需要用Mesh定制生成图形,而不用建模 ...
- Apache Spark 3.0 预览版正式发布,多项重大功能发布
2019年11月08日 数砖的 Xingbo Jiang 大佬给社区发了一封邮件,宣布 Apache Spark 3.0 预览版正式发布,这个版本主要是为了对即将发布的 Apache Spark 3. ...
- JDBD连接MySQL中的驱动与时区问题
1.在进行jdbc与mysql连接的时候应注意,加载驱动的方式根据MySQL版本内容来说 有变化 5.7版本之前: String driver= "com.mysql.jdbc.Driver ...
- PHP程序员-常用工具
三连问 经常有社区的同学问: “我的PHP程序有没有阻塞,我的PHP程序有没有开启协程(对自己写好的代码表示不自信),我的PHP程序有没有问题”.然后贴出了自己的程序,然后进入了愉快的灌水环节,随着时 ...
- jquery 判断数组是否为空
jquery 判断数组是否为空 if (data.length === 0) { console.log("数组为空"); }
- 使用Jquery获取指定属性的值
使用Jquery获取指定属性的值 <input type="hidden" value="{$time}" name="time" i ...
- 领扣(LeetCode)单调数列 个人题解
如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的. 如果对于所有 i <= j,A[i]> = ...
- 【dp】you are the one
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题解: 当最优解下, a1在j的位置排出, 则a2 ——aj-1 和 aj——an为两个独立事件 ...
- 推荐收藏系列:一文理解JVM虚拟机(内存、垃圾回收、性能优化)解决面试中遇到问题(图解版)
欢迎一起学习 <提升能力,涨薪可待篇> <面试知识,工作可待篇 > <实战演练,拒绝996篇 > 欢迎关注我博客 也欢迎关注公 众 号[Ccww笔记],原创技术文章 ...