题:http://acm.hdu.edu.cn/showproblem.php?pid=6736

题意:删掉一些边使得图不存在点双,求方案数。

分析:若一条边不属于点双,那么这条边有删和不删俩种选择,若找到点双,点双中必须删掉一条边(题目有保证一条边只能属于一个点双,所以不用担心一条边用于多个点双)tarjan找点双,若为点双则必须删掉点双中的一条边

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair<int,int>
const int M=3e5+;
const int mod=;
vector<int>g[M];
//vector<pii>bcc[M];
pii stk[M];
int low[M],dfn[M],tot,top,cnt;
ll countt[M];
void tarjan(int u,int f){
low[u]=dfn[u]=++tot;
for(int i=;i<g[u].size();i++){
int v=g[u][i];
pii e=make_pair(u,v);
if(!dfn[v]){
stk[++top]=e;
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
cnt++;
int len=top;
while(stk[top]!=e){
//bcc[cnt].pb(stk[top--]);
top--;
}
//bcc[cnt].pb(stk[top--]);
top--;
countt[cnt]=len-top;
}
}
else if(v!=f){
if(dfn[v]<dfn[u])
stk[++top]=e,low[u]=min(low[u],dfn[v]);
}
}
}
ll ksm(ll a,ll b){
ll t=1ll;
while(b){
if(b&)
t=(t*a)%mod;
b>>=;
a=(a*a)%mod;
}
return t;
}
ll mi[M];
int main(){
for(int i=;i<=M-;i++)
mi[i]=ksm(2ll,1ll*i);
//cout<<mi[3]<<endl;
int n,m;
while(~scanf("%d%d",&n,&m)){
tot=top=cnt=;
for(int i=;i<=n;i++)
low[i]=dfn[i]=,countt[i]=,g[i].clear();
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
g[u].pb(v);
g[v].pb(u);
}
for(int i=;i<=n;i++)
if(!dfn[i])
tarjan(i,-); ll ans=1ll;
// cout<<"cnt"<<cnt<<endl;
for(int i=;i<=cnt;i++){
if(countt[i]>){
ans*=mi[countt[i]]-;
m-=countt[i];
ans%=mod;
} }
if(m>=)
ans*=mi[m];
printf("%lld\n",ans%mod);
}
return ;
}

经验:得重新认识点双和边双,清楚定义

Forest Program(2019ccpc秦皇岛F)的更多相关文章

  1. 2019CCPC秦皇岛 F Forest Program

    队友过的:https://blog.csdn.net/liufengwei1/article/details/101632506 Forest Program Time Limit: 2000/100 ...

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

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

  3. 2019-ccpc秦皇岛现场赛

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

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

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

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

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

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

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

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

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

  8. HDU - 6736 F - Forest Program

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

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

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

随机推荐

  1. Java查漏补缺(3)(面向对象相关)

    Java查漏补缺(3) 继承·抽象类·接口·静态·权限 相关 this与super关键字 this的作用: 调用成员变量(可以用来区分局部变量和成员变量) 调用本类其他成员方法 调用构造方法(需要在方 ...

  2. XML--XML概览

    参考 https://www.cnblogs.com/fangjian0423/p/xml-namespace.html http://www.w3school.com.cn/x.asp xmlns ...

  3. vue/cli创建项目过程

            ①vue create demo    vue版本:3.9.3,node版本:12.8.0         ②Manually select features         ③Bab ...

  4. .NET CORE 热更新,否则提示DLL文件在使用中

    1.创建空目录,取名updatesite,里面放置app_ffline.htm文件,网站更新中访问使用,内容随意 2.updatesite目录下面创建Release目录,用于放置更新的dll文件 3. ...

  5. html标签title属性效果优化

    html标签title属性效果不友好,最致命的是响应慢,体验不好,JQuery-UI提供了很好的支持.在jquery.tip的基础上又做了修改,这样子定制效果更强. 代码如下: <!DOCTYP ...

  6. Python pip安装时You are using pip version 9.0.1, however version 18.0 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    在我们安装第三方库的时候会在结尾出现如下两行内容 You are using pip version 9.0.1, however version 18.0 is available. You sho ...

  7. 吴裕雄--天生自然 JAVASCRIPT开发学习:prototype(原型对象)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. python对数组缺失值进行填充

    1. 两个常用的函数 1.1 np.nonzero() np.nonzero()函数返回数组中不为False(0)的元素对应的索引 a = np.array([1,2,0,3,1,0]) print( ...

  9. CVPR2019 | 超越Mask R-CNN!华科开源图像实例分割新方法MS R-CNN

    安妮 乾明 发自 凹非寺 本文转载自量子位(QbitAI) 实习生又立功了! 这一次,亮出好成绩的实习生来自地平线,是一名华中科技大学的硕士生. 他作为第一作者完成的研究Mask Scoring R- ...

  10. Linux(CENTOS7) Jdk完整步骤安装

    方式一: 直接通过yum安装,这种方式比较方便,下面贴上安装jdk1.8*的命令: -openjdk* -y 上面命令执行完成之后,使用下面命令即可查看是否安装成功: java -version 方式 ...