POJ 3180 The cow Prom Tarjan基础题
题目用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基础题的更多相关文章
- poj 3180 The Cow Prom(强联通分量)
http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 3180 The Cow Prom(tarjan+缩点 easy)
Description The N ( <= N <= ,) cows are so excited: it's prom night! They are dressed in their ...
- POJ 3180 The Cow Prom(SCC)
[题目链接] http://poj.org/problem?id=3180 [题目大意] N头牛,M条有向绳子,能组成几个歌舞团?要求顺时针逆时针都能带动舞团内所有牛. [题解] 等价于求点数大于1的 ...
- [poj] 3180 the cow prom
原题 这是一道强连通分量板子题. 我们只用输出点数大于1的强连通分量的个数! #include<cstdio> #include<algorithm> #include< ...
- POJ 3180 The Cow Prom(强联通)
题目大意: 约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的 ...
- poj 2186: Popular Cows(tarjan基础题)
题目链接 tarjan参考博客 题意:求在图上可以被所有点到达的点的数量. 首先通过tarjan缩点,将所有内部两两可达的子图缩为一点,新图即为一个有向无环图(即DAG). 在这个DAG上,若存在不止 ...
- POJ 2186:Popular Cows Tarjan模板题
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25945 Accepted: 10612 De ...
- LuoGu-P2863牛的舞会The Cow Prom[tarjan 缩点模板]
传送门:https://www.luogu.org/problemnew/show/P2863 思路:tarjan模板题,之前会的tarjan,一直想学缩点到底是什么操作,发现就是把同组的放在一个数组 ...
- POJ 2186 受欢迎的牛 Tarjan基础题
#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #inc ...
随机推荐
- VM虚拟机里的Ubuntu系统怎么设置屏幕分辨率
说白了就是安装VMWare tools工具,步骤如下: 1)在VMWare中启动ubuntu虚拟机 2)在VMWare中:右键单击启动虚拟机,点击[安装vmware tools] 3)在ubuntu中 ...
- 汇编:输出寄存器AX中的内容
DATAS segment Temp db '0000H','$' DATAS ends CODES segment START: mov AX,DATAS mov DS,AX ;正式代码开始 mov ...
- JAVA / MySql 编程——第二章 初始MySQL
1. MySQL: ● MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL最流行的关系型数据库管理系统, ...
- 关于json输出为null?
原因: 该字符中含了ASCII码ETB控制符,即\x17导致json解析失败 解决方案: $params = preg_replace('/[\x00-\x1F]/', '', $params); ...
- 2019-04-11 python入门学习——配置机器及搭建开发环境
# 在windows操作系统中搭建python 3.x版本的开发环境,开发工具为 Anaconda 3. # 1.1 下载及安装Anaconda 3 Anaconda的特点:集成性高,包含很多常用的开 ...
- scrapy之分布式
分布式爬虫 概念:多台机器上可以执行同一个爬虫程序,实现网站数据的分布爬取. 原生的scrapy是不可以实现分布式爬虫? a) 调度器无法共享 b) 管道无法共享 工具 scrapy-redis组件: ...
- cf978E Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information ...
- Json的用处一
今天,我们用到了json的的用处,其实也就是一个很简单的用处,就是点击一个按钮,触发一个事件,然后调用json, 之后我们就可以进行异步操作,其实只是针对于后台的操作,其实我们并没有对数据库进行刷新, ...
- 7 Django的模板层
你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(request): now = datet ...
- 3,版本控制git-多人协作
如果你想获得一份已经存在了的 Git 仓库的拷贝,比如说,你想为某个开源项目贡献自己的一份力,这时就要用到 `git clone` 命令. 如果你对其它的 VCS 系统(比如说Subversion)很 ...