【强连通分量】Bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
Description
约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞.
Sulotion
裸强连通分量,我就测试下模板。。
Code
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+; int pre[maxn],low[maxn],clock;
int bcc[maxn],size[maxn],cnt;
int head[maxn],e[maxn],nxt[maxn],k;
int adde(int u,int v){
e[++k]=v,nxt[k]=head[u];
head[u]=k;
}
int a[maxn],t;
int n,m; int dfs(int u){
pre[u]=low[u]=++clock;
a[++t]=u;
for(int i=head[u];i;i=nxt[i]){
int v=e[i];
if(!pre[v]){
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(!bcc[v]){
low[u]=min(low[u],pre[v]);
}
}
if(low[u]==pre[u]){
++cnt;
while(t){
bcc[a[t]]=cnt;
size[cnt]++;
if(a[t--]==u) break;
}
}
} int main(){
scanf("%d%d",&n,&m);
int u,v;
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
adde(u,v);
} for(int i=;i<=n;i++)
if(!pre[i]) dfs(i); int ans=;
for(int i=;i<=cnt;i++)
if(size[i]>) ans++;
printf("%d\n",ans); return ;
}
【强连通分量】Bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会的更多相关文章
- bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in ...
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan
1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec Memory Limit: 64 MB Description The N (2 & ...
- bzoj:1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in ...
- 【BZOJ1654】[Usaco2006 Jan]The Cow Prom 奶牛舞会 赤果果的tarjan
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in ...
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
- P1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
裸的强连通 ; type node=record f,t:longint; end; var n,m,dgr,i,u,v,num,ans:longint; bfsdgr,low,head,f:arra ...
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】
几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...
- 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...
- bzoj1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏
金组题什么的都要绕个弯才能AC..不想银组套模板= = 题目大意:给n个点,求最小边长使得此正方形内的点数不少于c个 首先一看题就知道要二分边长len 本来打算用二维前缀和来判断,显然时间会爆,而且坐 ...
随机推荐
- 《深入理解JAVA虚拟机》笔记1
java程序运行时的内存空间,按照虚拟机规范有下面几项: )程序计数器 指示下条命令执行地址.当然是线程私有,不然线程怎么能并行的起来. 不重要,占内存很小,忽略不计. )方法区 这个名字很让我迷惑. ...
- Spring Aop 梳理
Aspect Oriented Programming 面向切面编程.解耦是程序员编码开发过程中一直追求的.AOP也是为了解耦所诞生. 具体思想是:定义一个切面,在切面的纵向定义处理方法,处理完成之 ...
- Visual Studio Live Share不完全指北
Visual Studio Live Share是什么? 是VS的一个实时协作开发的扩展工具. github地址:https://github.com/MicrosoftD...文档地址:https: ...
- C++位运算
移位运算 要点 1 它们都是双目运算符,两个运算分量都是整形,结果也是整形. 2 " < <" 左移:右边空出的位上补0,左边的位将从字头挤掉,其值相当于乘2. ...
- Java 包装类笔记
@(JDK)[包装类] Java 包装类笔记 当需要使用到集合的时候,如果是基础数据类型,需要转换为包装类,再使用,在JDK1.5之前,每次使用的时候,都需要手动转换为包装类(称为装箱),然后在使用的 ...
- vue实现淘宝商品详情页属性选择功能
方法一是自己想出来的,方法二来自忘记哪里看到的了 不知道是不是你要的效果: 方法一:利用input[type="radio"] css代码: input { display: no ...
- HTML 学习笔记 day one
HTML学习笔记 day one Chapter one 网站开发基础 1.2网站的基本架构 网站的基本要素:内容,页面,超链接 动态网页和静态网页的区别在于:动态网页会自动更新,后缀名是.asp或者 ...
- php 阿里云短信服务及阿里大鱼实现短信验证码的发送
一:使用阿里云的短信服务 ① 申请短信签名 ②申请短信模板 ③创建Access Key,获取AccessKeyId 与 AccessKeySecret.(为了安全起见,这里建议使用子用户的Access ...
- java项目获取根路径(web项目和application项目的区分)
Java项目中经常要读取配置文件,涉及到读取配置文件的地方,就会要读定位文件的路径.因此,在项目如何正确获取文件路径尤为关键. 根据不同的java项目,在获取文件路径时候有一些 小区别 测试环境:E: ...
- 火狐兼容window.event.returnValue=false;
火狐中window.event是未定义的,可用e.preventDefault();替代window.event.returnValue=false; 直接上图