题意:找强连通中点数大于2的强连通分量个数

思路:Tarjan

// By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,ans=0,t=0,cnt=0,tot=1,top=0,dfn[50050],low[50050],p[10050],s[10050];
int xx,yy,jy,first[10050],next[50050],v[50050];
bool vis[50050];
void add(int x,int y){v[tot]=y;next[tot]=first[x];first[x]=tot++;}
void tarjan(int x){
dfn[x]=low[x]=++cnt;vis[x]=1,s[++top]=x;
for(int i=first[x];i;i=next[i])
if(!dfn[v[i]])tarjan(v[i]),low[x]=min(low[x],low[v[i]]);
else if(vis[v[i]])low[x]=min(low[x],dfn[v[i]]);
if(dfn[x]==low[x]){t++;do jy=s[top--],vis[jy]=0,p[t]++;while(jy!=x);}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)scanf("%d%d",&xx,&yy),add(xx,yy);
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
for(int i=1;i<=n;i++)if(p[i]>=2)ans++;
printf("%d\n",ans);
}

POJ 3180 Tarjan的更多相关文章

  1. poj 3180 The Cow Prom(tarjan+缩点 easy)

    Description The N ( <= N <= ,) cows are so excited: it's prom night! They are dressed in their ...

  2. POJ 3180 The cow Prom Tarjan基础题

    题目用google翻译实在看不懂 其实题目意思如下 给一个有向图,求点个数大于1的强联通分量个数 #include<cstdio> #include<algorithm> #i ...

  3. poj 3180 The Cow Prom(强联通分量)

    http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  4. POJ 2762 tarjan缩点+并查集+度数

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15494 ...

  5. POJ 2672 Tarjan + 缩点 + 拓扑思想

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17383 ...

  6. POJ 3180 The Cow Prom(SCC)

    [题目链接] http://poj.org/problem?id=3180 [题目大意] N头牛,M条有向绳子,能组成几个歌舞团?要求顺时针逆时针都能带动舞团内所有牛. [题解] 等价于求点数大于1的 ...

  7. POJ 3694 tarjan 桥+lca

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7298   Accepted: 2651 Descripti ...

  8. poj 2186 tarjan求强连通分量

    蕾姐讲过的例题..玩了两天后才想起来做 貌似省赛之后确实变得好懒了...再努力两天就可以去北京玩了! 顺便借这个题记录一下求强连通分量的算法 1 只需要一次dfs 依靠stack来实现的tarjan算 ...

  9. POJ 3180 The Cow Prom(强联通)

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

随机推荐

  1. JQuery学习笔记系列(一)----选择器详解

    笔者好长时间没有更新过博客园的笔记了,一部分原因是去年刚刚开始工作一段时间忙碌的加班,体会了一种每天加班到凌晨的充实感,之后闲暇时间了也因为自己懒惰没有坚持记笔记的习惯,现在重新拾起来. 借用古人的一 ...

  2. 【Oracle】查询当前SCN

    介绍两种方式: 一.sys用户下: select current_scn from v$database; select dbms_flashback.get_system_change_number ...

  3. sqlserver 分组 group by

    select 名称, COUNT(名称) as 数量之和from 信息group by all 名称

  4. strusts2_json

    引用别人的 Struts.xml <package name="default" extends ="json-default" > <act ...

  5. CSS3实现1前端常用Loading效果

    此页动画效果都是gif图的,不想用代码写的话,下载图片就可使用. 第1种效果: 代码如下 <div class="loading"> <span></ ...

  6. .apply和.call用法和区别

    apply:方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args)方法能接收两个参数obj:这个对象将代替Function类里this对象args:这 ...

  7. 在fedora「27」下,安装mysql 问题总结

    有时会出现,没有mysql.sock,不存在的问题, Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. ...

  8. POJ 2486 Apple Tree (树形dp 经典题)

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const ...

  9. THUWC2019 划水记

    Day -2 在学校呆了inf天之后终于回家了! Day 0 在家无(tui)所(fei)事(mo)事(yu),顺便被拉出去剪了个头发,想写写thusc2017的题也写不动,一直在网上冲浪,到处乱翻以 ...

  10. Javascript解析URL

    举个栗子,一个网页的URL为https://i.cnblogs.com/EditPosts.aspx?opt=1,要分离出通信协议.host.port.path.query.hash等值.这时候我们应 ...