题目用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. 【学时总结】 ◆学时·IV◆ 数位DP

    [学时·IV] 数位DP ■基本策略■ 说白了就是超时和不超时的区别 :) 有一些特别的题与数位有关,但是用一般的枚举算法会超时.这时候就有人提出了--我们可以用动态规划!通过数字前一位和后一位之间的 ...

  2. 轻量级自动化工具 pssh

    pssh应用场景 pssh是一个用python编写的可以并发在多台服务器上批量执行命令的工具,它支持文件并行复制,远程并行执行命令,其中文件并行复制是pssh的核心功能,也是同类工具中的一个亮点. 要 ...

  3. datatable常用设置

    bSort: false, // 是否排序功能 bFilter: false, // 过滤功能 bPaginate: true, // 翻页功能 bInfo: true, // 页脚信息 bProce ...

  4. 对于未来学习Linux的决心书,以此为鉴

    学习Linux的决心书 我叫曹佳佳,来自祖国的大西北甘肃庆阳,2016年大专毕业之后从事自己的专业风力发电行业工作了两年多在从事风电行业的过程中越来越感觉到自己的薪资待遇和以后的发展空间越来越小,而且 ...

  5. 【c学习-1】

    #include<stdio.h> int main(){ int a,b,max; printf("请输入两个整数:"); //格式化输出函数 scanf(" ...

  6. centos7重启apache、nginx、mysql、php-fpm命令

    apache启动systemctl start httpd停止systemctl stop httpd重启systemctl restart httpd mysql启动systemctl start ...

  7. MySQL 获取物理表的主键字段

    参考代码: /** * 获取主键字段 * @param $table * @param $database * @return mixed */ public function get_primary ...

  8. JZOJ 1738. Heatwave

    Description 给你N个点的无向连通图,图中有M条边,第j条边的长度为: d_j. 现在有 K个询问. 每个询问的格式是:A B,表示询问从A点走到B点的所有路径中,最长的边最小值是多少? I ...

  9. Python系列6之面向对象

    目录 生成器和迭代器 字符串格式化 内置函数vars 反射 面向对象编程 一. 生成器和迭代器  1. 生成器 生成器具有一种生成的能力,它仅仅代表着一种生成的能力,当我们需要使用的时候,才会通过迭代 ...

  10. 选择排序算法Java实现

    一. 算法描述 选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换,第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1 ...