裸的强连通

 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. 向MyEclipse添加Oracle数据库

    向MyEclipse添加Oracle数据库 1.点击下面圈起来的位置,打开MyEclipse database Explorer视图. 2.在如图空白处右击,选择new进入New Database C ...

  2. 【KMP原理】【整理回顾】

    今儿套KMP模板做了个题,敏敏找我讲next[]数组的时候把我问懵了.具体原理都记不清了光靠模板凑得了一时凑不了一世啊,所以再捋一捋顺一顺,这次印象要深刻一点了: KMP与暴力匹配的优化区别就不再提了 ...

  3. 【最短路】ACdream 1198 - Transformers' Mission

    Problem Description A group of transformers whose leader is Optimus Prime(擎天柱) were assigned a missi ...

  4. hdu 4614 线段树

    思路:当k为1的时候,用二分法查询包含有f个空瓶的上界r,然后更新会方便很多,直接更新区间(a,r)了. #include<iostream> #include<cstdio> ...

  5. echars3.0 柱状图大小设置

    { name:'百度', type:'bar', barWidth : 10, stack: '搜索引擎', data:[620, 732, 701, 734, 1090, 1130, 1120] } ...

  6. Java Concurrency - Callable & Future

    One of the advantages of the Executor framework is that you can run concurrent tasks that return a r ...

  7. 用Dalvik指令集写个java类

    Dalvik指令集 .class public LCalculate;#定义类名 .super Ljava/lang/Object;#定义父类 .method public static main([ ...

  8. android用异步操作AsyncTask编写文件查看器

    Activity程序 package com.example.fileasynctaskproject; import java.io.File; import java.util.ArrayList ...

  9. VS2013 打开项目时出现 未定义标识符string的解决办法

    ---恢复内容开始--- 前两天从前辈那儿弄到一份源码,VC 6时期写出来的mfc程序. 打开之后直接编译编译成功,可以运行.但是看代码的时候却发现出现了好多错误,如 未定义标识符string,NUL ...

  10. Today’s words

    transcendental,transcendental capacity commission,the commission would keep venetian unimodel transi ...