bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】
几乎是板子,求有几个size>1的scc
直接tarjan即可
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=10005;
int n,m,h[N],cnt,ans,tmp,dfn[N],low[N],s[N],top;
bool v[N];
struct qwe
{
int ne,to;
}e[N*10];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=v;
h[u]=cnt;
}
void tarjan(int u)
{
dfn[u]=low[u]=++tmp;
v[s[++top]=u]=1;
for(int i=h[u];i;i=e[i].ne)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[u]=min(low[u],low[e[i].to]);
}
else if(v[e[i].to])
low[u]=min(low[u],dfn[e[i].to]);
}
if(low[u]==dfn[u])
{
int sum=0;
while(s[top]!=u)
{
v[s[top--]]=0;
sum++;
}
v[s[top--]]=0;
if(sum)
ans++;
}
}
int main()
{
n=read(),m=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read();
add(x,y);
}
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i);
printf("%d",ans);
return 0;
}
bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】的更多相关文章
- 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 ...
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
- 【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 ...
- 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 ...
- 【强连通分量】Bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
Description 约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的 ...
- 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 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- BZOJ——1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏
http://www.lydsy.com/JudgeOnline/problem.php?id=1720 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1 ...
随机推荐
- keil mdk uvision使用技巧
语法检测&代码提示 中文友好: tab 可以选中一大块代码,一起缩进 快速注释 先选中你要注释的代码区,然后右键,选择Advanced,Comment Selection 就可以了 查找替换 ...
- STM32F407 开发环境搭建 程序下载 个人笔记
详细资料: http://www.openedv.com/thread-13912-1-1.html 需要安装的软件: 1.keil(MDK,必选),用keygen破解 2.CH340驱动,(usb串 ...
- Windows 10 & Game Bar & YouTube & video records
Windows 10 & Game Bar & YouTube & video records Windows 10 C:\Users\xgqfrms\Videos\Captu ...
- HTML5 & CSS3 & font-family
HTML5 & CSS3 & font-family 中文字体的英文名称 宋体* SimSun 黑体* SimHei 微软雅黑* Microsoft YaHei 微软正黑体 http: ...
- Django:(7)auth用户认证组件 & 中间件
用户认证组件 用户认证组件: 功能:用session记录登陆验证状态 前提:用户表:django自带的auth_user 创建超级用户的命令: python manage.py createsuper ...
- 【ZJOI2017 Round1练习】D7T1 graph(提答)
题意: n<=1000 m<=10000 思路:
- PHP 关键词
PHP 关键词 TCP 传输层通信协议 面向连接的.可靠的.基于字节流的 建立链接需要三次握手 Socket(套接字) 一个工具,一个接口 封装了TCP/IP协议 建立长链接的基础 HTTP 一个应用 ...
- SPFA 算法
百度百科: http://baike.baidu.com/link?url=O0QvxbOY8SVBjrIl6nF6EvMHSslgcEIxfXSoty5SbkA7QjbWZjTWARzwTQsKKb ...
- [bzoj4278][ONTAK2015]Tasowanie_后缀数组_贪心
Tasowanie bzoj-4278 ONTAK-2015 题目大意:给定两个字符串,求两个字符串二路归并之后生成的字典序最小的字符串是什么. 注释:$1\le len_1,len_2\le 2\c ...
- P1765 手机_NOI导刊2010普及(10)
P1765 手机_NOI导刊2010普及(10) 题目描述 一般的手机的键盘是这样的: 1 2 abc 3 def 4 ghi 5 jkl 6 mno 7 pqrs 8 tuv 9 wxyz * 0 ...