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 ...
随机推荐
- LeetCode105. Construct Binary Tree from Preorder and Inorder Traversal
题目 根据一棵树的前序遍历与中序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 例如,给出 前序遍历 preorder = [3,9,20,15,7] 中序遍历 inorder = [9,3 ...
- ubuntu修改IP地址和网关的方法
一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...
- spring-mvc.xml的定时器配置
<!-- 设置时间 --> <bean id="myJobTrigger" class="org.springframework.scheduling. ...
- 微信小程序本地缓存
- Python常用函数记录
Python常用函数/方法记录 一. Python的random模块: 导入模块: import random 1. random()方法: 如上如可知该函数返回一个[0,1)(左闭右开)的一个随机的 ...
- 《python编程从入门到实践》第七章笔记
用户输入和while循环 1.函数input():让程序停止运行,等待用户输入一些文本.接受一个参数,既即要向用户显示的提示或说明. 2.将数值输入用于计算和比较前,务必将其转换为数值表示. 3.fo ...
- Fruits【水果】
Fruits Many of us love July because it's the month when nature's berries and stone fruits are in abu ...
- python—— 文件的打开模式和文件对象方法 & os、os.path 模块中关于文件、目录常用的函数使用方法
引用自“鱼c工作室” 文件的打开模式和文件对象方法 : https://fishc.com.cn/forum.php?mod=viewthread&tid=45279&ext ...
- Background Segment CNT
CNT简介 CNT算法是OpenCV Contrib 模块中的背景减除(Background segment)算法之一.相较于OpenCV提供的其他背景减 除算法,该算法具有运行速度快,检测精度高等优 ...
- 3 Mongodb数据查询1
1.基本查询 方法find():查询 db.集合名称.find({条件文档}) 方法findOne():查询,只返回第一个 db.集合名称.findOne({条件文档}) 方法pretty():将结果 ...