几乎是板子,求有几个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】的更多相关文章

  1. 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 & ...

  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 ...

  3. 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...

  4. 【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 ...

  5. 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 ...

  6. 【强连通分量】Bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会

    Description 约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞.     只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的 ...

  7. 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 ...

  8. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  9. 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 ...

随机推荐

  1. 嵌入式linux启动信息完全注释

    嵌入式linux启动信息完全注释 from:http://www.embedlinux.cn/ShowPost.asp?ThreadID=377 摘要 我们在这里讨论的是对嵌入式linux系统的启动过 ...

  2. 关于必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用异常问题

    问题描述: 下午调试代码的时候突然发现页面突然异常了,原本以为是代码哪里写错了,后来通过定位发现MVC,UI界面的Linq异常,即关于必须添加对程序集“System.Runtime, Version= ...

  3. JavaWeb 项目,更改本地文件需刷新才有效问题 (tomcat相关)

    问题 如果JavaWeb项目需要读取实时更新的本地文件内容,可能遇到必须在更新后手动refresh才能有效的问题. 原因 这是由于项目实际上是运行在Tomcat中,而非本地的工作目录.eclipse可 ...

  4. android 的Manifest对图标的影响

    转自 http://blog.csdn.net/yuan1590/article/details/6700683 先看看网路上的说法: Android.intent.action.MAIN决定应用程序 ...

  5. [K/3Cloud] 使用操作还是服务

    现在菜单点击事件既可以挂操作又可以挂服务,那到底是应该挂操作还是服务呢? 有个需求是要求一个动作可以在两个时点被触发 1.单据由下推或选单生成的时候: 2.点击单据界面功能菜单: 这样是不是需要做一个 ...

  6. hunnu - 11545 小明的烦恼——找路径 (最大流)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11545 只是要求不经过相同的边,那么每次找出一条增广路T-- ...

  7. HashMap的工作原理以及代码实现,为什么要转换成红黑树?

    原理参考:https://blog.csdn.net/striveb/article/details/84657326 总结: 为什么当桶中键值对数量大于8才转换成红黑树,数量小于6才转换成链表? 参 ...

  8. Ubuntu 16.04错误:正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/ppa.launchpad.net_t-tujikawa_ppa_ubuntu_dists_xenial_main_i18n_Translatio

    错误: 正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /va ...

  9. ThinkPHP3.2 点击看不清刷新验证码

    欢迎使用Markdown编辑器写博客 baidu了一下.发现没有可用的源码,自己想了想,以下的方法可行. <!DOCTYPE html> <html> <head> ...

  10. 对一个deb包的解压、改动、又一次打包全过程方法

    /*********************************************************************  * Author  : Samson  * Date   ...