[poj] 3180 the cow prom
这是一道强连通分量板子题。
我们只用输出点数大于1的强连通分量的个数!
#include<cstdio>
#include<algorithm>
#include<stack>
#define N 10010
#define M 50010
using namespace std;
int n,m,head[N],dfn[N],low[N],cnt=1,t,sum,bel[N],num[N],out[N],ans;
bool instk[N];
stack <int> stk;
struct hhh
{
int to,next;
}edge[M];
int read()
{
int ans=0,fu=1;
char j=getchar();
for (;(j<'0' || j>'9') && j!='-';j=getchar()) ;
if (j=='-') fu=-1,j=getchar();
for (;j>='0' && j<='9';j=getchar()) ans*=10,ans+=j-'0';
return ans*fu;
}
void add(int u,int v)
{
edge[cnt].to=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void Tarjan(int x)
{
dfn[x]=low[x]=++t;
stk.push(x);
instk[x]=1;
int v;
for (int i=head[x];i;i=edge[i].next)
{
v=edge[i].to;
if (!dfn[v])
{
Tarjan(v);
low[x]=min(low[x],low[v]);
}
else if (instk[v]) low[x]=min(low[x],dfn[v]);
}
if (dfn[x]==low[x])
{
sum++;
do
{
v=stk.top();
stk.pop();
instk[v]=0;
bel[v]=sum;
num[sum]++;
}while(v!=x);
}
}
int main()
{
n=read();
m=read();
for (int i=1,a,b;i<=m;i++)
{
a=read();
b=read();
add(a,b);
}
for (int i=1;i<=n;i++)
if (!dfn[i]) Tarjan(i);
for (int i=1;i<=sum;i++)
if (num[i]>1) ans++;
printf("%d",ans);
return 0;
}
[poj] 3180 the cow prom的更多相关文章
- 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(强联通)
题目大意: 约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的 ...
- POJ 3180 The cow Prom Tarjan基础题
题目用google翻译实在看不懂 其实题目意思如下 给一个有向图,求点个数大于1的强联通分量个数 #include<cstdio> #include<algorithm> #i ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- POJ 3180
The Cow Prom Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1132 Accepted: 713 Descr ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- bzoj1654 / P2863 [USACO06JAN]牛的舞会The Cow Prom
P2863 [USACO06JAN]牛的舞会The Cow Prom 求点数$>1$的强连通分量数,裸的Tanjan模板. #include<iostream> #include&l ...
随机推荐
- BZOJ3884: 上帝与集合的正确用法(欧拉函数 扩展欧拉定理)
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3860 Solved: 1751[Submit][Status][Discuss] Descripti ...
- c# 解决读取Excel混合文本类型,数据读取失败的解决方法
错误重现: ----------------------------------------------------------------------- 在导入Excel读取数据时,其中的一个字段保 ...
- Hive学习路线图
- Python 中关于文件操作的注意事项
文件操作 #打开文件 f = open('要打开的文件路径',mode = 'r/w/a', encoding = '文件原来写入时的编码') #操作 data = f.read() #读取 f.wr ...
- C语言进阶——关于07中指针的补充
首先我们应该了解指针可以分为: 野指针: 野指针不是NULL指针,是未初始化或未清零的指针,他指向的内存地址不是程序员想要的.人们一般不会错用NULL指针,因为用if语句很容易判断.但是“野指针”是很 ...
- proteus中蜂鸣器不响的原因
本文参考自https://blog.csdn.net/gin_love/article/details/51168369 此网站.在用proteus仿真报警电路时,发现蜂鸣器不响.后在网上找了 ...
- 012---Django的用户认证组件
知识预览 用户认证 回到顶部 用户认证 auth模块 ? 1 from django.contrib import auth django.contrib.auth中提供了许多方法,这里主要介绍其中的 ...
- 使用perl发邮件
如果你使用的是 window 系统,没有 sendmail 工具.这时你就可以使用 perl 的 MIME:Lite 模块作为邮件客户端来发送邮件. 这里我们直接用 cpan 来安装(需要 root ...
- python判断mongodb--find(),find_one()返回是否为空
conn = MongoClient('127.0.0.1', 27017)db = conn.diffcollection = db['test1']result = collection.find ...
- Vue_自定义指令
关于Vue的自定义指令: - 在Vue中除了核心功能默认内置的指令(v-model & v-show) - Vue也允许注册自定义指令. 注意,在 Vue2.0 中,代码复用和抽象的主要形式是 ...