P2863 [USACO06JAN]牛的舞会The Cow Prom

求点数$>1$的强连通分量数,裸的Tanjan模板。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int min(int &a,int &b){return a<b?a:b;}
#define N 10002
#define M 50002
int n,m,clo,dfn[N],low[N],blo,be[N],tp,st[N],ans;
int cnt,hd[N],nxt[M<<],ed[N],poi[M<<];
void adde(int x,int y){
nxt[ed[x]]=++cnt; hd[x]=hd[x]?hd[x]:cnt;
ed[x]=cnt; poi[cnt]=y;
}
void tarjan(int x){
dfn[x]=low[x]=++clo; st[++tp]=x;
for(int i=hd[x];i;i=nxt[i]){
int to=poi[i];
if(!dfn[to]){
tarjan(to);
low[x]=min(low[x],low[to]);
}else if(!be[to]) low[x]=min(low[x],dfn[to]);
}
if(dfn[x]<=low[x]){
int tot=;
be[x]=++blo;
while(st[tp]!=x) be[st[tp--]]=blo,++tot;
--tp; ans+=(tot>);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=,q1,q2;i<=m;++i)
scanf("%d%d",&q1,&q2),adde(q1,q2);
for(int i=;i<=n;++i) if(!dfn[i]) tarjan(i);
printf("%d",ans);
return ;
}

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

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

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

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

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

  3. 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 ...

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

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

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

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

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

    题目传送门 这个题还是个缩点的板子题...... 答案就是size大于1的强连通分量的个数 加一个size来统计就好了 #include <iostream> #include <c ...

  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. 170817、Nginx详细配置

    Nginx能做什么 nginx主要是做转发,当然也可以做静态资源文件缓存,做转发的时候,比如你有几个url,可以统一通过走nginx,然后通过nginx转发到不同的url上 1.反向代理 反向代理应该 ...

  2. POJ 1417 - True Liars - [带权并查集+DP]

    题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having ...

  3. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. MySQL升级方法一

    1.在目标服务器上安装新版本的mysql数据库. 1)解压缩新版mysql数据库压缩包并cp到指定目录: [root@faspdev mnt]# tar -zxvf mysql-5.6.24-linu ...

  5. zabbix 报警的返回值

    常用: {DATE} {ESC.HISTORY} {EVENT.AGE} {EVENT.DATE} {EVENT.ID} {EVENT.TIME} {HOSTNAME} {IPADDRESS} {IT ...

  6. android adt自带eclipse无法设置ndk路径

    android sdk官网下载r23版本的adt时自带的eclipse没有设置ndk路径的地方,通过Install New Software 发现无法更新,那么如何解决这个问题呢?     软件百度云 ...

  7. 实现 TensorFlow 架构的规模性和灵活性

    TensorFlow https://mp.weixin.qq.com/s/tEyX596WXTzsABXaeTesug

  8. WordCount优化

    Github 地址:chaosrings/wcPro 1.PSP2.1表格 psp 2.1 psp阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 10 Estimate 估计这 ...

  9. SQL语句中的正则表达式

    正则表达式 REGEXP_LIKE执行正则表达式匹配 SELECT FIRST_NAME FROM EMPLOYEES WHERE REGEXP_LIKE(FIRST_NAME,'^al(an|yss ...

  10. bzoj4129 Haruna’s Breakfast 莫队

    这个思想不难理解了前面几个就能懂 但是代码比较复杂,大概会和之前几次碰到难题的时候一样,一步步思考下去,然后把难点分成好几个板块讲下qwq 首先读入这颗树,预处理下lca,然后就分块,这个时候就会碰到 ...