Forest Program(2019ccpc秦皇岛F)
题: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)的更多相关文章
- 2019CCPC秦皇岛 F Forest Program
队友过的:https://blog.csdn.net/liufengwei1/article/details/101632506 Forest Program Time Limit: 2000/100 ...
- [CCPC2019秦皇岛] F. Forest Program
[CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...
- 2019-ccpc秦皇岛现场赛
https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...
- 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\) 个环,问去掉一 ...
- 2019CCPC秦皇岛赛区(重现赛)- F
链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=872 题意: Z 国近年来一直在考虑遏制国土沙 ...
- HDU - 6736 F - Forest Program
题意 给你n个点m条边,并且保证整个图是仙人掌. 仙人掌:每条边仅属于1条或者0条回路 且无重边和自环 让你删掉一些边使其变成一棵树(拥有点数-1条边) 注意一个点也是森林 图可能是不联通的 思路 考 ...
- 2019CCPC秦皇岛 E题 Escape(网络流)
Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
随机推荐
- POJ 1125:Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64 ...
- 小白学习之pytorch框架(7)之实战Kaggle比赛:房价预测(K折交叉验证、*args、**kwargs)
本篇博客代码来自于<动手学深度学习>pytorch版,也是代码较多,解释较少的一篇.不过好多方法在我以前的博客都有提,所以这次没提.还有一个原因是,这篇博客的代码,只要好好看看肯定能看懂( ...
- dd if= of= MBR
1.备份分区表信息 sudo fdisk -l >hda.txt #分区表信息重定向输出到文件中 2.备份MBR sudo dd if=/dev/sda of=mbr bs=512 count ...
- SpringCloud学习之Config分布式配置中心(八)
统一配置中心概述 如果微服务架构中没有使用统一配置中心时,所存在的问题: 配置文件分散在各个项目里,不方便维护 配置内容安全与权限,实际开发中,开发人员是不知道线上环境的配置的 更新配置后,项目需要重 ...
- ADO多线程数据库查询
{ADO查询多线程单元} unit ADOThread; interface uses Classes,StdCtrls,ADODB; type TADOThread = class(TThread) ...
- 谷歌 notification 测试 页面
<button onclick="notifyMe('master wei','http://cdn.sstatic.net/stackexchange/img/logos/so/so ...
- nodejs(6)express学习
1.简单认识express express::一个快速的网站开发框架,封装了原生的http模块,用起来更方便:API更人性化 特点 基于Node.js平台之上,进一步封装了 http 模块,从而提供了 ...
- Centos配置NAT模式下的静态ip
一.查看所在的ip段 点击 编辑-->虚拟网卡编辑器 选中vmware8网卡,点击 DHCP设置 二.编辑网卡配置文件 查看网卡 ip addr 命令打开配置文件 vi /etc/sysconf ...
- 计算机网络(4): socket select使用:聊天室模版
知识点: 如上所示,用户首先将需要进行IO操作的socket添加到select中,然后阻塞等待select系统调用返回.当数据到达时,socket被激活,select函数返回.用户线程正式发起read ...
- main函数的参数(int argc,char *argv[])
一般的main函数都是不带参数的,因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这两个参 ...