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. PAT-GPLT L1-039 - 古风排版 - [字符串输入输出]

    题目链接:https://www.patest.cn/contests/gplt/L1-039 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standar ...

  2. python 将字符串转换为字典

    在一般的工程处理中,需要将获取的字符串数据转换为字典,这样处理起来会非常方便. 我获取的是json数据: content = {"corpus_no":"64702772 ...

  3. svm核函数的理解和选择

    https://blog.csdn.net/leonis_v/article/details/50688766 特征空间的隐式映射:核函数    咱们首先给出核函数的来头:在上文中,我们已经了解到了S ...

  4. 2018/04/02 每日一个Linux命令 之 新建/修改/删除群组

    -- 新建群组 groupadd [群组名] -- 修改群组名称 groupmod [群组名] [新群组名] -n 修改组名 -g 修改组识别码 -- 删除群组 groupdel [删除的组名] --

  5. nginx 哈希表数据结构

    1.哈希表ngx_hash_t的优势和特点 哈希表是一种典型的以空间换取时间的数据结构,在没有冲突的情况下,对任意元素的插入.索引.删除的时间复杂度都是O(1).这样优秀的时间复杂度是通过将元素的ke ...

  6. linux find 命令

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  7. spring boot配置service发布服务

    在application.yml中配置 server: port: 8080 context-path: /crm spring: datasource: driver-class-name: com ...

  8. idea 使用方法

    1:设置自定义自动补全,使用$END$代表最后光标所在的位置. http://blog.csdn.net/u012569796/article/details/54694418 2:使用 shift+ ...

  9. sdut2613(This is an A+B Problem)大数加法(乘法)

    #include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>u ...

  10. R实现的最小二乘lsfit函数学习

    1.源码 function (x, y, wt = NULL, intercept = TRUE, tolerance = 1e-, yname = NULL) { x <- as.matrix ...