[luoguP2863] [USACO06JAN]牛的舞会The Cow Prom(Tarjan)
有向图,找点数大于1的强连通分量个数
——代码
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream> const int MAXN = ;
int n, m, cnt, idx, size, ans;
int head[MAXN], to[MAXN << ], next[MAXN << ];
int dfn[MAXN], low[MAXN], belong[MAXN], tot[MAXN];
bool ins[MAXN];
std::stack <int> s; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline int min(int x, int y)
{
return x < y ? x : y;
} inline void add(int x, int y)
{
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
} inline void dfs(int u)
{
int i, v;
s.push(u);
ins[u] = ;
dfn[u] = low[u] = ++idx;
for(i = head[u]; i ^ -; i = next[i])
{
v = to[i];
if(!dfn[v])
{
dfs(v);
low[u] = min(low[u], low[v]);
}
else if(ins[v]) low[u] = min(low[u], dfn[v]);
}
if(low[u] == dfn[u])
{
size++;
do
{
v = s.top();
s.pop();
ins[v] = ;
belong[v] = size;
}
while(u ^ v);
}
} int main()
{
int i, x, y;
n = read();
m = read();
memset(head, -, sizeof(head));
for(i = ; i <= m; i++)
{
x = read();
y = read();
add(x, y);
}
for(i = ; i <= n; i++)
if(!dfn[i])
dfs(i);
for(i = ; i <= n; i++) tot[belong[i]]++;
for(i = ; i <= size; i++)
if(tot[i] > )
ans++;
printf("%d\n", ans);
return ;
}
[luoguP2863] [USACO06JAN]牛的舞会The Cow Prom(Tarjan)的更多相关文章
- luoguP2863 [USACO06JAN]牛的舞会The Cow Prom
P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...
- [USACO06JAN]牛的舞会The Cow Prom Tarjan
题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...
- 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 ...
- bzoj1654 / P2863 [USACO06JAN]牛的舞会The Cow Prom
P2863 [USACO06JAN]牛的舞会The Cow Prom 求点数$>1$的强连通分量数,裸的Tanjan模板. #include<iostream> #include&l ...
- P2863 [USACO06JAN]牛的舞会The Cow Prom
洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...
- [USACO06JAN] 牛的舞会 The Cow Prom
题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...
- 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom
https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...
- [USACO06JAN]牛的舞会The Cow Prom
题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...
随机推荐
- bzoj 2442: [Usaco2011 Open]修剪草坪【单调栈】
设f[i]为i不选的最小损失,转移是f[i]=f[j]+e[i[(i-j-1<=k) 因为f是单调不降的,所以f[j]显然越靠右越好因为i-j-1<=k的限制,所以单调栈需要弹栈 #inc ...
- VUE学习之计算属性computed
计算属性:computed 先看一下官网的说法 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div id="ex ...
- Quartz定时调度jar包的执行Demo分享
1.Quartz简介 Quartz框架的核心是调度器.调度器负责管理Quartz应用运行时环境.调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件.Quartz不仅仅是线程和线程管理. ...
- 个人作品:EasyPicker(轻取)简洁而又实用的文件收取Web应用
EasyPicker简洁实用且方便的在线文件收取Web应用 小弟我作为班上的学委,有一个伟大的职责,收发各科作业(尤其是专业课的上机课),上机==写报告,此时就产生了实验报告这个玩意儿,一个班少则4 ...
- Authorization 头信息为空的解决方案
在 Apache配置添加SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=此次问题完美解决.
- MvcPager 分页控件
官方教程: http://www.webdiyer.com/mvcpager
- POJ 2773 欧几里得
思路: 若a和b互素的话,则b*t+a和b一定互素 用周期性做就好了 //By SiriusRen #include <cstdio> using namespace std; ],m,k ...
- docker血一样的教训,生成容器的时候一定要设置数据卷,把数据文件目录,配置文件目录,日志文件目录都要映射到宿主机上保存啊!!!
打个比方,比如mysql,如果你想重新设置一下mysql的配置,不小心配错里,启动容器失败,已启动就停止了. 根本进不去mysql的容器里.如果之前run容器的时候,没有把数据文件,日志文件,配置文件 ...
- Window对象与DOM
目前,前端插件数不胜数,比如有移动端滑动特效插件Swiper,下拉刷新的iScroll,弹出框插件layer,还有我们经常使用的JQuery,jquery.mobile等,这些插件能够满足我们日常的基 ...
- Android 性能优化(13)网络优化( 9)Determining and Monitoring the Docking State and Type
Determining and Monitoring the Docking State and Type PreviousNext This lesson teaches you to Determ ...