裸的强连通

 const maxe=;
type
node=record
f,t:longint;
end;
var n,m,dgr,i,u,v,num,ans:longint;
bfsdgr,low,head,f:array[..maxe] of longint;
b:array[..maxe] of node;
p:array[..maxe] of boolean;
procedure insert(u,v:longint);
begin
with b[i] do
begin
f:=head[u];
t:=v;
end;
head[u]:=i;
end;
procedure tarjan(x:longint);
var e,v:longint;
begin
inc(dgr);
e:=head[x]; if e= then exit;
inc(num);
bfsdgr[x]:=dgr; low[x]:=dgr;
f[num]:=x; p[x]:=true;
//
while e<> do
begin
v:=b[e].t;
if bfsdgr[v]= then
begin
tarjan(v);
if low[v]<low[x] then low[x]:=low[v];
end
else if (p[v]) and (bfsdgr[v]<low[x]) then
low[x]:=bfsdgr[v];
e:=b[e].f;
end;
if bfsdgr[x]=low[x] then
begin
inc(ans);
//writeln(x);
//repeat
while f[num]<>x do
begin
p[f[num]]:=false;
dec(num);
end;
//until f[num]=x;
end;
end;
begin
readln(n,m);
for i:= to m do
begin
readln(u,v);
insert(u,v);
end;
fillchar(bfsdgr,sizeof(bfsdgr),);
fillchar(p,sizeof(p),false);
for i:= to n do
if bfsdgr[i]= then tarjan(i);
writeln(ans);
end.

(转载请注明出处:http://www.cnblogs.com/Kalenda/)

P1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会的更多相关文章

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

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

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

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

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

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

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

  7. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】

    几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...

  8. 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法

    [BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...

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

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  2. 关于Java中的构造方法和set方法()给属性赋值

    对于一个类中的成员变量(属性),属性如果都设置成了private类型,那么对外给属性设置了get和set方法 , 那么外部程序中给这些属性设置值,有两种方式. 第一种就是通过set()方法. 第二种就 ...

  3. hdu 4670 树的点分治

    思路:首先当然是要用树的点分治了.根节点为root,那么经过root的合法路径数求出来这题就解决了.因为我们可以用分治枚举根,最后将所有根的路径数加起来就是结果.当然这里的根不是整棵树的根,是子树根. ...

  4. hdu 4638 树状数组

    思路:将查询区间按右节点的升序排列,然后插入第i个数的时候,若nun[i]+1已经插入,那么就update(pre[num[i]+1],-1):pre[]表示的是该数的位置.同样若 num[i]-1存 ...

  5. C++STL学习笔记_(4)queue

    10.2.5Queue容器 Queue简介 ²  queue是队列容器,是一种"先进先出"的容器. ²  queue是简单地装饰deque容器而成为另外的一种容器. ²  #inc ...

  6. 为Widget添加事件

      原帖:http://bbs.51cto.com/thread-965565-1-1.html 在appWidget中,ImageButton和Button都是被支持的控件,其事件可分成三种类型: ...

  7. HTTP 错误 500.21 - Internal Server Error 处理程序“PageHandlerFactory-Integr

    将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序"PageHandlerFactory-Integr"在 ...

  8. VHD轻松实现双系统

    VHD 是微软虚拟磁盘文件.   VHD(Microsoft Virtual Hard Disk format). 目前可以使用Microsoft Virtual PC 2007 and Micros ...

  9. cocos2dx-lua class语法糖要注意了

    cocos2dx-lua function.lua 定义了class方法,让lua实现继承像传统语言一样漂亮和方便 看定义 function class(classname, super) local ...

  10. Eclipse Code Templates设置

    从工作开始,经历了几个项目的开发,现在的项目一般都是一个团队共同开发,而每个人都有自己的编码习惯,为了统一格式,项目组在项目开发之前都会制定一系列的规范.俗话说约定优于配置,但是在执行过程中往往发现效 ...