【强连通分量】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 本来打算用二维前缀和来判断,显然时间会爆,而且坐 ...
随机推荐
- Oracle官方文档学习路线图
- SQL语言逻辑执行顺序
SQL语言逻辑执行顺序 2012-12-18 16:18:13 分类: 数据库开发技术 查询的逻辑执行顺序 FROM < left_table> ON < join_conditio ...
- OSGI介绍
OSGI介绍 OSGI简介 OSGI (Open Service Gateway Initiative)联盟成立于1999 年,它是一个非盈利的国际组织,旨在建立一个开放的服务规范,为通过网络向设备提 ...
- 窗口函数解决数据岛问题(mysql暂无窗口函数,可以通过用户变量解决窗口函数问题)
数据岛问题: 有表: create table dataisland (id int) insert into dataisland values(1),(2),(3),(7),(11),(12) ...
- 电商网站开发记录(三) Spring的引入,以及配置详解
1.web.xml配置注解<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=& ...
- Android Studio 2.3 instant run与miui冲突问题的解决
Android Studio最近发布的2.3版本,由于这个版本改进后的Instant Run功能和很多国内ROM存在兼容问题,所以导致不得不做一些妥协策略,具体在小米Rom上,就是把小米rom的调试定 ...
- Microsoft源代码注释语言(SAL)提供设置批注
Microsoft源代码注释语言(SAL)提供设置批注可以使用描述的功能如何使用其参数,它对其假设并确保它使其在完成. 批注可标头文件 <sal.h>定义. Visual Studio C ...
- 前后台分离部署时,Niginx上的部署
upstream bowenpay_backend { server 127.0.0.1:9002; } server { listen 80; server_name wx.bowenpay.com ...
- PHP_保留两位小数并且四舍五入(可用于精度计算)_保留两位小数并且不四舍五入
小数例子: PHP保留两位小数并且四舍五入 1 $n=0.1265489; 2 echo sprintf("%.2f", $n); // 0.13 大家可以看到我们用到了sprin ...
- 3、js无缝滚动轮播
另一个无缝滚动轮播,带暂停,由于js是异步,用C面向过程的思想开始会很怪异很怪异,因为当你定时器里面需要执行的函数时间比较长或是有一段延时时,异步的代码会完全不同,但习惯就好了. 这个代码有几个问题, ...