[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 1854: [Scoi2010]游戏【匈牙利算法】
没啥可说的,就是一边属性一边道具建二分图,把两个属性都连到道具上,然后枚举匹配,如果无法匹配就输出,时间戳优化 #include<iostream> #include<cstdio& ...
- 17年day3
/* 嗯,又一天. 时日无多了,还能蹦哒几天? 上午依旧考试,日常挂T1,读错题.还是好困. 兔子说明天晚上要请我们吃水饺~~~~去年就没这待遇. 下午打开邮箱一看,咦?嗯. 昨晚做噩梦NOIP考了状 ...
- [App Store Connect帮助]六、测试 Beta 版本(4.2) 管理 Beta 版构建版本:查看构建版本状态和指标
必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能.“开发者”职能或“营销”职能.请参见职能权限. 在首页上,点按“我的 App”,选择您的 App,然后在工具栏中点按“TestFlig ...
- Django day 34 过滤课程,登录,redis,python操作redis
一:过滤课程, 二:登录 三:redis, 四:python操作redis
- linux centos7安装mysql
1.下载并安装官方的 yum repository (新建了mysql文件夹) wget -i -c http://dev.mysql.com/get/mysql57-community-releas ...
- C++函数重载的4种错误示例
函数重载的4种错误示例: #include <iostream> #include <string> using namespace std; //函数重载 同函数名,函数重载 ...
- [Code+#1]大吉大利,晚上吃鸡!
输入输出样例 输入样例#1: 7 7 1 7 1 2 2 2 4 2 4 6 2 6 7 2 1 3 2 3 5 4 5 7 2 输出样例#1: 6 输入样例#2: 5 5 1 4 1 2 1 1 3 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)
题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...
- 转】 mysql5.6.12 for Linux安装
原博文出自于: http://blog.csdn.net/book_mmicky/article/details/25714049 感谢! 1:上www.mysql.org下载64位版本mysql5. ...
- jQuery学习笔记(2)-选择器的使用
一.选择器是什么 有了jQuery的选择器,我们几乎可以获取页面上任意一个或一组对象 二.Dom对象和jQuery包装集 1.Dom对象 JavaScript中获取Dom对象的方式 <div i ...