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. POJ-1959 Darts

    Darts Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1286 Accepted: 741 Description Back ...

  2. hdu5954 Do not pour out【积分】【二分】【待补.....】

    2016沈阳区域赛http://acm.hdu.edu.cn/showproblem.php?pid=5954 Do not pour out Time Limit: 2000/1000 MS (Ja ...

  3. PyQT5-QCheckBox按钮

    """ QcheckBox:单选框有两种状态:开和关.通常跟标签一起使用,用在一些激活或者关闭的场景 Author:dengyexun DateTime:2018.11. ...

  4. pstools psexec mimikatz

    Psexec原理 - oneVs1的专栏 - 博客频道 - CSDN.NET 在远程终端(3389.mstsc.exe).虚拟桌面中抓取密码的方法: 通常你在远程终端中运行该程序会提示:存储空间不足, ...

  5. iOS - UITableView 编辑(cell的插入, 删除, 移动)

    UITableView Cell的插入/删除 核心API Class : UITableView Delegate : UITableViewDataSource, UITableViewDelega ...

  6. es新增字段,并设置默认值

    重新设置mapping 添加新的字段. 设置es允许脚本执行:elasticsearch.yml script.inline: true 然后执行脚本 POST linewell_assets_mgt ...

  7. 【python-opencv】15-图像阈值

    [微语]立志要如山,行道要如水.不如山,不能坚定,不如水,不能曲达 import cv2 as cv import numpy as np from matplotlib import pyplot ...

  8. 如何用 Keynote 制作动画演示(转)

    原文:如何用 Keynote 制作动画演示 Keynote 里的很多特效可以用来制作效果不错的演示,一页页的将需要演示的内容交代清楚后,直接输出成 m4v 的视频格式,为了方便贴到博客或者发布到 Tw ...

  9. DOM对象与Jquery对象转换

    dom对象的样式是这么加的(js) .style.background = “red”; jquery对象样式是这么加的(jq) .css(“background”,”red”); <div i ...

  10. 多线程下载文件,ftp文件服务器

    1: 多线程下载文件 package com.li.multiplyThread; import org.apache.commons.lang3.exception.ExceptionUtils; ...