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 ...
随机推荐
- VS安装
1. 只更改工作负载和单个组件 工作负载:我只勾选3个需要的 单个组件: 勾选 .NET 下Framework 别的不用改 2.点击安装,安装完成重启
- 关于手机微信端ios的input不能选中问题解决方案
最近在做一个微信端的商城,以前做web端的比较多,手机端做的相对来说要少点,老板说让我用俗称”靠谱的移动前端框架”—-AUI来搭建项目. 当时觉得用不用框架无所谓啦.结果后来写到一半把项目发布到手机上 ...
- JVM集训-----内存结构
一.程序计数器/PC寄存器 (Program Counter Registe) 用于保存当前正在执行的程序的内存地址(下一条jvm指令的执行地址),由于Java是支持多线程执行的,所以程序执行的轨迹不 ...
- JavaScript返回格式化的时间字符串
http://www.w3school.com.cn/jsref/jsref_getMinutes.asp 由 getMinutes() 返回的值是一个两位的数字.不过返回值不总是两位的,如果该值小于 ...
- js数组和集合互转
js数组和集合互转可用于去重: 数组转集合 var arr = [55, 44, 65]; var set = new Set(arr); console.log(set.size === arr ...
- Unittest框架的从零到壹(二)
四大重要概念 在unittest文档中有四个重要的概念:Test Case.Test Suite.Test Runner和Test Fixture.只有理解了这几个概念,才能理解单元测试的基本特征. ...
- Win10如何快速截屏
Win10不用QQ,如何快速截屏? 年轻的时候想截图总是需要把QQ打开,但是直到我遇到了一种尴尬的场景:就是需要我把鼠标放着标签上,才会有下一步内容出现,这就很难搞. 经过查找资料,做出一些总结. 第 ...
- scikit-learn_cookbook1: 高性能机器学习-NumPy
源码下载 在本章主要内容: NumPy基础知识 加载iris数据集 查看iris数据集 用pandas查看iris数据集 用NumPy和matplotlib绘图 最小机器学习配方 - SVM分类 介绍 ...
- Fortran流程控制与逻辑运算、循环--xdd
1.IF语句 1 if() then ... end if 2 if() then ... else ... end if 3 if() then ... else if() then ... els ...
- 今天是python专场UDP socket 链接
type = SOCK_DGRAM UDP 协议的通信优势 允许一个服务器的同时和多个客户端通信 server import socket sk = socket.socket(type=socket ...