LuoGu-P2863牛的舞会The Cow Prom[tarjan 缩点模板]
传送门:https://www.luogu.org/problemnew/show/P2863
思路:tarjan模板题,之前会的tarjan,一直想学缩点到底是什么操作,发现就是把同组的放在一个数组里(并查集可能又会有),或者重新建图;不知道为什么百度不到讲缩点的blog。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator> #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
typedef long long ll; using namespace std; const int maxn = ;
int n,m;
vector<int >mp[maxn];
int dfn[maxn],low[maxn],ind;
int stk[maxn],p;
bool vis[maxn];
int ans = , cnt = ;
int q[maxn];
void tarjan(int x)
{
ind++;
dfn[x] = low[x] = ind;
vis[x] = true;
stk[++p] = x; for(int i=;i<mp[x].size();i++)
{
int to = mp[x][i];
if(dfn[to]==)
{
tarjan(to);
low[x] = min(low[x],low[to]);
}
else if(vis[to])
{
low[x] = min(low[x],dfn[to]);
}
}
if(low[x]==dfn[x])
{
cnt++; while()
{ int tmp = stk[p--];
q[cnt]++;
vis[tmp]=false;
if(tmp==x)break;
}
}
}
int main(){
scanf("%d%d", &n,&m);
for(int i=; i<=m; i++)
{
int u,v;
scanf("%d%d", &u,&v);
mp[u].pb(v);
}
for(int i=; i<=n; i++)
{
if(dfn[i]==)
{
tarjan(i);
}
}
for(int i=;i<=cnt;i++)
if(q[i]>)ans++;
printf("%d\n",ans); return ;
}
LuoGu-P2863牛的舞会The Cow Prom[tarjan 缩点模板]的更多相关文章
- 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 ...
- [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 ...
- luoguP2863 [USACO06JAN]牛的舞会The Cow Prom
P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...
- 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom
https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...
- 【luogu P2863 [USACO06JAN]牛的舞会The Cow Prom】 题解
题目链接:https://www.luogu.org/problemnew/show/P2863 求强连通分量大小>自己单个点的 #include <stack> #include ...
- LuoGu P2863 [USACO06JAN]牛的舞会The Cow Prom
题目传送门 这个题还是个缩点的板子题...... 答案就是size大于1的强连通分量的个数 加一个size来统计就好了 #include <iostream> #include <c ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...
随机推荐
- 虚IP解决程序连只读服务器故障漂移
目前公司有一套核心交易数据库配置了AlWaysON,SQL 2012版本, 1主4从, 其从库(8,14, 8.15) 这2台只读的从数据库服务器, 后台程序和wms等很多程序,都是直接配置IP连接这 ...
- 【Java】You have an error in your SQL syntax ...
详情如下: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server v ...
- openGL基本概念
OpenGL自身是一个巨大的状态机(State Machine):一系列的变量描述OpenGL此刻应当如何运行.OpenGL的状态通常被称为OpenGL上下文(Context).我们通常使用如下途径去 ...
- jplayer
简介 jplayer是个用JavaScript写的完全免费和开源的媒体库(media library).作为jQuery插件的一员,使用jPlayer可以在你的网页上轻松加入跨平台的音乐和视频 使用方 ...
- 内容汇总(c语言)
一,内容 常量(整型,浮点型,字符型,字符串型,符号常量) 变量(基本类型:整形,浮点型,字符型,枚举型:构造类型:数组,结构体,共用体:另外还有指针类型和NULL) 顺序结构 分支结构 循环结构 当 ...
- Cell Phone Networ (树形dp-最小支配集)
目录 Cell Phone Networ (树形dp-最小支配集) 题意 思路 题解 Cell Phone Networ (树形dp-最小支配集) Farmer John has decided to ...
- ORACLE 的CONNECT BY、START WITH,CONNECT_BY_ROOT、CONNECT_BY_ISLEAF、SYS_CONNECT_BY_PATH,LEVEL的使用(Hierarchical query-层次查询)
如果表中存在层次数据,则可以使用层次化查询子句查询出表中行记录之间的层次关系基本语法: START WITH <condition1> CONNECT BY [ NOCYCLE ] < ...
- python基础之变量与数据类型
变量在python中变量可以理解为在计算机内存中命名的一个存储空间,可以存储任意类型的数据.变量命名变量名可以使用英文.数字和_命名,且不能用数字开头使用赋值运算符等号“=”用来给变量赋值.变量赋值等 ...
- 对比度拉伸(一些基本的灰度变换函数)基本原理及Python实现
1. 基本原理 对比度拉伸是扩展图像灰度级动态范围的处理.通过在灰度级中确定两个点来控制变换函数的形状.下面是对比度拉伸函数中阈值处理的代码示例,阈值为平均值. 2. 测试结果 图源自skimage ...
- Eclipse+CXF框架开发Web服务实战
一. 说明 采用CXF框架开发webservice. 所用软件及版本如下. 操作系统:Window XP SP3. JDK:JDK1.6.0_07,http://www.oracle.com/ ...