裸的强连通

 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. toad for oracle 快捷键 转

    序号 功能说明 快捷键 备注 1 隐藏查询结果 F2 2 查看对象详细信息 F4 3 清空屏幕 F7 4 调出以前执行的sql命令 F8 5 执行全部sql F9 6 直接执行当前sql CTRL+E ...

  2. poj 1679 次小生成树

    次小生成树的求法: 1.Prime法 定义一个二维数组F[i][j]表示点i到点j在最小生成树中的路径上的最大权值.有个知识就是将一条不在最小生成树中的边Edge加入最小生成树时,树中要去掉的边就是E ...

  3. truncate 函数用法示例

    --Oracle trunc()函数的用法 /**************日期********************/ select trunc(sysdate) from dual --2015- ...

  4. Sherlock and The Beast

    Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diaboli ...

  5. Apache ab 测试工具使用(一)

    简述: 试用apache ab测试工具 下载点 http://httpd.apache.org/download.cgi 参考: http://jingyan.baidu.com/article/e3 ...

  6. 学习css简单内容

    Css的class,ID和上下文选择符 Class选择符. Class选择符用来配置某一类css规则,将其应用到网页中一个或多个区域.配置一类样式时,要将选择符配置成类名.在类名前加(.).类名必须以 ...

  7. overflow:hidden清除浮动原理解析及清除浮动常用方法总结

    最近在看<CSS Mastery>这本书,里面有用overflow:hidden来清理浮动的方法.但是一直想不明白为什么能够实现清除浮动,查阅了网络上的解释,下面来总结一下. 一.首先来想 ...

  8. (干货)Linux学习资源推荐

    源地址 国内的专业Linux网站(GB) ChinaUnix Linux中国 实验楼: 免费提供了Linux在线实验环境,不用在自己机子上装系统也可以学习Linux,超方便实用!. 国内的专业Linu ...

  9. Office升级到2013版后无法登录微软账号问题

    自打office从2010版升级到2013版,就再也无法登录微软账号了.每次点击登录,弹出来的框就显示:this feature has been disabled by your administr ...

  10. 制作BibTex文件

    上一篇日志中讲到了在LaTeX中使用BibTex管理参考文献,这篇日志具体总结下如何制作BibTex文件. 制作BibTex文件,主要有以下几种方法: 手工制作: 直接从期刊数据库中下载: 借助Goo ...