题目用google翻译实在看不懂

其实题目意思如下

给一个有向图,求点个数大于1的强联通分量个数

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
#define M 50010
#define N 10010
using namespace std;
int n,m,u,v,head[N],cnt=,ans,sz[N],belong[N],dfn[N],low[N],indx,tar;
bool inst[N];
stack <int> st;
struct edge
{
int u,v;
}e[M];
void add(int u,int v)
{
e[cnt].v=v;
e[cnt].u=head[u];
head[u]=cnt++;
}
void dfs(int u)
{
dfn[u]=low[u]=++indx;
inst[u]=;
st.push(u);
for (int i=head[u];i;i=e[i].u)
{
int v=e[i].v;
if(!dfn[v])
{
dfs(v);
low[u]=min(low[u],low[v]);
}
else
if (inst[v])
low[u]=min(low[u],dfn[v]);
}
if (dfn[u]==low[u])
{
tar++;
while ()
{
int t=st.top();
st.pop(),inst[t]=;
sz[tar]++;
belong[t]=tar;
if (t==u)
break;
}
}}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
add(u,v);
}
for (int i=;i<=n;i++)
if (dfn[i]==) dfs(i);
for (int i=;i<=tar;i++)
ans+=sz[i]>;
printf("%d",ans);
return ;
}

POJ 3180 The cow Prom Tarjan基础题的更多相关文章

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

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

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

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

  3. POJ 3180 The Cow Prom(SCC)

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

  4. [poj] 3180 the cow prom

    原题 这是一道强连通分量板子题. 我们只用输出点数大于1的强连通分量的个数! #include<cstdio> #include<algorithm> #include< ...

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

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

  6. poj 2186: Popular Cows(tarjan基础题)

    题目链接 tarjan参考博客 题意:求在图上可以被所有点到达的点的数量. 首先通过tarjan缩点,将所有内部两两可达的子图缩为一点,新图即为一个有向无环图(即DAG). 在这个DAG上,若存在不止 ...

  7. POJ 2186:Popular Cows Tarjan模板题

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25945   Accepted: 10612 De ...

  8. LuoGu-P2863牛的舞会The Cow Prom[tarjan 缩点模板]

    传送门:https://www.luogu.org/problemnew/show/P2863 思路:tarjan模板题,之前会的tarjan,一直想学缩点到底是什么操作,发现就是把同组的放在一个数组 ...

  9. POJ 2186 受欢迎的牛 Tarjan基础题

    #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #inc ...

随机推荐

  1. Web as a App(Web既APP)的概念可以提出吗?

    Web as a App (WaaA),Web既APP.灵感出于SaaS.PaaS.IaaS等~ 最近在做一个PC项目,即便我的项目是to B的,用户量没那么大,但是我仍然很注重性能及用户体验,我把我 ...

  2. scrapy--dytt(电影天堂)

    喜欢看电影的小伙伴,如果想看新的电影,然后没去看电影院看,没有正确的获得好的方法,大家就可以在电影天堂里进行下载.这里给大家提供一种思路. 1.dytt.py # -*- coding: utf-8 ...

  3. Linux crontab 实现秒级定时任务

    1   crontab 的延时: 原理:通过延时方法 sleep N  来实现每N秒执行. crontab -e 输入以下语句,然后 :wq 保存退出. * * * * * /usr/bin/curl ...

  4. 快速排序算法Java实现

    1) 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行 示例: package ...

  5. Android 自定义圆形图片 CircleImageView

    1.效果预览 1.1.布局中写自定义圆形图片的路径即可 1.2.然后看一看图片效果 1.3.原图是这样的 @mipmap/ic_launcher 2.使用过程 2.1.CircleImageView源 ...

  6. 6,Flask 中内置的 Session

    Flask中的Session非常的奇怪,他会将你的SessionID存放在客户端的Cookie中,使用起来也非常的奇怪 1. Flask 中 session 是需要 secret_key 的 from ...

  7. 用for循环计算(1-3+5-7...99)的结果(两种方法)

    1) sum=0 count=1 for i in range(1,100,2): if count % 2==0: sum = sum - i else: sum = sum + i count = ...

  8. 质数,$\varphi$和$\mu$线性筛

    typedef long long ll; bool check[N]; int mu[N],pri[N],tot; ll phi[N]; void init(int lim){ check[]=,p ...

  9. 【02】webstorm配置babel转换器+截图(by魔芋)

    [02]webstorm配置babel转换器+截图(by魔芋)   [02]魔芋的安装过程     01,配置babel.   02,用webstorm.注意webstorm的版本号.   03,使用 ...

  10. unbantu安装wmvare

    最新评论 wsmyyjie:写的太好了!!! zhangmin92:回复 wopapa523: 这个是你用另一.. wopapa523:请问i11是在哪里输入的? myh65013:挺深入的 andk ...