裸的强连通

 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. controller,link,compile不同

    测试案例 .directive('testDirective', function() { return { restrict: 'E', template: '<p>Hello {{nu ...

  2. Redis 命令 - Server

    BGREWRITEAOF Asynchronously rewrite the append-only file BGSAVE Asynchronously save the dataset to d ...

  3. 转....导入excel错误:外部表不是预期的格式 解决方案

    环境:win7+iis7+Office2007 在asp.net网站中导出Excel文件后,再把文件导入到数据库中. 读取Excel文件时,打开连接出错. 错误为:外部表不是预期的格式 解决:检查了一 ...

  4. Ghost版Win8.1系统企业版下载

    host版Win8.1系统企业版,下载完成后一定要使用校验工具验证GHO文件MD5值,如果不符请不要安装,不然安装失败后果自负.GHO文件路径一定不要带中文,否则无法安装.安装完成第一次进入桌面会黑屏 ...

  5. Oracle 一些操作

    Achivelog ============================ alter system set db_recovery_file_dest='F:\ORACLE\recovery_ar ...

  6. 第三篇、image 设置圆角的几种方式

    第一种: 就拿view来举例 view.layer.masksToBounds=YES; //设置为yes,就可以使用圆角 view.layer.cornerRadius= ; //设置它的圆角大小 ...

  7. iOS - 文件与数据(File & Data)

    01 推出系统前的时间处理 --- 实现监听和处理程序退出事件的功能 //视图已经加载过时调用 - (void)viewDidLoad { [super viewDidLoad]; // Do any ...

  8. js 获取 当前时间 时间差 时间戳 倒计时

    开发web一段时间后发现经常使用时间进行一些操作,比较多的就是获取当前时间.对时间进行比较.时间倒计时.时间戳这些部分,每次去用经常忘总是需要去查询,还是自己总结一下比较靠谱. 获取时间戳的方法: 第 ...

  9. CodeSmith Template Model Output

    背景:上学那会儿就接触CodeSmith,是一款非常优秀的代码自动生成工具.以前写过好些基本模版,可惜早不知道扔到哪儿去了,如今只能重新开始,把它捡回来,加油. 效果:将数据库 DataBase 应用 ...

  10. Base64编码原理与应用

    本文内容转自网络,如需详细内容,请参考相关网址. http://my.oschina.net/goal/blog/201032 代码参考:http://blog.csdn.net/prsniper/a ...