题目传送门

这个题还是个缩点的板子题......

答案就是size大于1的强连通分量的个数

加一个size来统计就好了

#include <iostream>
#include <cstdlib>
#include <cstdio> using namespace std; const int N=1e5+5;
const int M=5e5+5; struct edge{
int to,next;
}e[M]; int n,m,dfn[N],low[N],cnt,head[N];
int idx[N],s[N],top,tot,sum,siz[N];
bool ins[N];int ind[N],ans; inline void build(int u,int v){
e[++tot].next=head[u];
head[u]=tot;e[tot].to=v;
return ;
} inline void tarjan(int cur){
s[++top]=cur;ins[cur]=true;
dfn[cur]=low[cur]=++cnt;
for(int i=head[cur];i;i=e[i].next){
int k=e[i].to;
if(!dfn[k]){
tarjan(k);
low[cur]=min(low[cur],low[k]);
}else if(ins[k]) low[cur]=min(low[cur],dfn[k]);
}
if(low[cur]==dfn[cur]){
register int ss=0;
++sum;
while(s[top+1]!=cur){
++ss;
idx[s[top]]=sum;
ins[s[top--]]=false;
}
siz[sum]=ss;
}
return ;
} int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i){
register int u,v;
scanf("%d%d",&u,&v);
build(u,v);
}
for(int i=1;i<=n;++i) if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;++i)
for(int j=head[i];j;j=e[j].next){
int k=e[j].to;
if(idx[i]!=idx[k]) ++ind[idx[k]];
}
for(int i=1;i<=sum;++i) if(!ind[i]&&siz[i]>1) ++ans;
printf("%d\n",ans);
return 0;
}

LuoGu P2863 [USACO06JAN]牛的舞会The Cow Prom的更多相关文章

  1. luogu P2863 [USACO06JAN]牛的舞会The Cow Prom |Tarjan

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  2. 【luogu P2863 [USACO06JAN]牛的舞会The Cow Prom】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2863 求强连通分量大小>自己单个点的 #include <stack> #include ...

  3. bzoj1654 / P2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 求点数$>1$的强连通分量数,裸的Tanjan模板. #include<iostream> #include&l ...

  4. P2863 [USACO06JAN]牛的舞会The Cow Prom

    洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...

  5. 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom

    https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...

  6. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom

    传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...

  7. 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom

    代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...

  8. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom 题解

    每日一题 day11 打卡 Analysis 好久没大Tarjan了,练习练习模板. 只要在Tarjan后扫一遍si数组看是否大于1就好了. #include<iostream> #inc ...

  9. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom(Tarjan)

    一道tarjan的模板水题 在这里还是着重解释一下tarjan的代码 #include<iostream> #include<cstdio> #include<algor ...

随机推荐

  1. 【八】虚拟机工具 01 jps命令详解

    JPS 名称: jps - Java Virtual Machine Process Status Tool 命令用法: jps [options] [hostid] options:命令选项,用来对 ...

  2. Java8新特性 重复注解与类型注解

    import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.anno ...

  3. mesg命令帮助文档(ubuntu 18.04)

    MESG() User Commands MESG() NAME mesg - display (or do not display) messages from other users SYNOPS ...

  4. 俄罗斯方块部分功能(Java)

    package OO.day01; public class TetrisCell { int totalRow = 20; int totalcol = 10; //定义横宽 int row; in ...

  5. [译]使用mediatR的notification来扩展的的应用

    原文 你不希望在controller里面出现任何领域知识 开发者经常有这样的疑问"这个代码应该放在哪呢?"应该使用仓储还是query类?.... 怎么去实现职责分离和单一职责呢? ...

  6. sublime text 3 3103 注册码

    —– BEGIN LICENSE —– Ryan Clark Single User License EA7E-812479 2158A7DE B690A7A3 8EC04710 006A5EEB 3 ...

  7. window 编译lua 5.3

    由于lua 5.1 不支持左移右移的操作符,所以要移植lua 5.3.方便在window 下编译调试 参考链接: http://www.linuxidc.com/Linux/2014-02/96459 ...

  8. Failed to read artifact ......明明之前可以的

    Type One or more constraints have not been satisfied. mybaits Failed to read artifact ....jar 右键proj ...

  9. mysql 查询优化 ~ 优化基础补充

    一 简介:此文章是对于 sql通用基础的补充说明 二 虚拟列: mysql虚拟列是mysql5.7的新特性,对于函数计算形成的结果可作为虚拟列,并可以对虚拟列添加索引,这样就能加速sql的运行,不过有 ...

  10. 错误整理:No plugin found for prefix 'jetty' in the current project and in the plugin groups

    在maven进行jetty的调试中出现错误: [ERROR] No plugin found for prefix 'jetty' in the current project and in the ...