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 ...
随机推荐
- Eclipse编写JavaFX环境配置
配置eclipse用于写JavaFX:1.确定JRE中有jfxrt.jar---jdk82.选中项目-->属性-->Java Build Path3.Libraries-->jre包 ...
- django+xadmin在线教育平台(八)
4-5 user modesl.py设计 循环引用: 设计app时每个app都有model mark 如图:我们在user中定义usercourse记录用户学习的课程.会有两个外键:user和co ...
- tomcat7下载地址
tomcat7下载地址:https://tomcat.apache.org/download-70.cgi
- Uncaught Error: Script error for "popper.js", needed by: bootstrap - require.js
Uncaught Error: Script error for "popper.js", needed by: bootstrap https://requirejs.org/d ...
- 45.VUE学习之--组件之父组件使用scope定义子组件模板样式结构实例讲解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 交叉编译qt5.6
按照网上的攻略编译QT5.6 https://www.lijingquan.net/2016/07/08/build-kernel-busybox-qt5-6-tslib-imx28/ 出现问题,找不 ...
- C# 在窗口绘制图形(打点、画圆、画线)
需要包含命名空间 using System.Drawing; 画图前需要先创建画板 void Display() { Graphics g = this.CreateGraphics(); //创建画 ...
- 大话卷积神经网络(CNN)
这几年深度学习快速发展,在图像识别.语音识别.物体识别等各种场景上取得了巨大的成功,例如AlphaGo击败世界围棋冠军,iPhone X内置了人脸识别解锁功能等等,很多AI产品在世界上引起了很大的 ...
- MyBatis---集合查询(一对多)
这里的集合查询即一对多的数据联合查询.如一个用户多次登录的信息查询 要实现这样的联合查询需要在用户实体类中添加登录实体类的一个集合属性字段,表中不存在该字段. <resultMap id=&qu ...
- json对象和java对象的相互转换方法(json-lib、jackson、fastjson、gson)
一 使用json-lib包下的JSONObject和JSONArray转换 代码如下: package com.test.test; import java.util.ArrayList; impor ...