【强连通分量】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 本来打算用二维前缀和来判断,显然时间会爆,而且坐 ...
随机推荐
- Ocelot中文文档-Websockets
Ocelot额外支持代理websockets.这个功能在问题 212中被提出. 为了是Ocelot代理websocket,你需要做如下事情. 在你的Configure方法中,你要告知应用程序使用Web ...
- ThinkPHP5从零基础搭建CMS系统(二)
接上节,开启wamp集成环境,在浏览器地址栏输入http://localhost/cms/public,即可运行项目,但是这边域名太长,做一下处理. 注:需要查看tp5全部教程,请点击右侧thinkp ...
- Redis实际开发中常见问题
首先redis作为缓存,一般作为缓存有2个用途,快速访问和减少IO频率,所谓减少IO频率就是等缓存积累到一定大小然后一次刷入磁盘进行持久化. 一般的设计就是客户端往数据库里更新或者读写数据,redis ...
- (三)SpringBoot基础篇- 持久层,jdbcTemplate和JpaRespository
一.介绍 SpringBoot框架为使用SQL数据库提供了广泛的支持,从使用JdbcTemplate的直接JDBC访问到完整的"对象关系映射"技术(如Hibernate).Spri ...
- (一)SpringBoot基础篇- 介绍及HelloWorld初体验
1.SpringBoot介绍: 根据官方SpringBoot文档描述,BUILD ANYTHING WITH SPRING BOOT (用SPRING BOOT构建任何东西,很牛X呀!),下面是官方文 ...
- Reactor三种线程模型与Netty线程模型
文中所讲基本都是以非阻塞IO.异步IO为基础.对于阻塞式IO,下面的编程模型几乎都不适用 Reactor三种线程模型 单线程模型 单个线程以非阻塞IO或事件IO处理所有IO事件,包括连接.读.写.异常 ...
- Python_语法和界面设计
http://www.runoob.com/python/python-gui-tkinter.html http://www.python-course.eu/python_tkinter.php
- python_黑洞数
>>> def main(n): start = 10**(n-1)+2 end = start*10-20 for i in range(start,end): i = str(i ...
- 微信小游戏开发之四:使用three.js引擎
一.前言 微信小游戏中最魔性的'跳一跳'就是基于three.js 引擎开发的 源码放到github上了:GitHub地址 请自行下载. 二.下载 three.min.js 打开页面,复制代码到本地 ...
- PAT1003:Emergency
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...