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 ...
随机推荐
- Linux平台 Oracle 19c RAC安装Part1:准备工作
一.实施前期准备工作 1.1 服务器安装操作系统 1.2 Oracle安装介质 1.3 共享存储规划 1.4 网络规范分配 二.安装前期准备工作 2.1 各节点系统时间校对 2.2 各节点关闭防火墙和 ...
- angularjs通信以及postmessage与iframe通信
这篇文章是用markdown工具写的,有需要的可以使用vscode打开 # angularjs 控制器.组件之间的通信 ## 一.基于事件的方式 此方式下,主要通过 angularjs 内置指令` ...
- 华为路由交换综合实验 ---IA阶段
目录 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 根据拓扑合理规划IP地址以及VLANIf地址(PC1属于运营部,PC2属于市场 ...
- 关于python中的特殊方法
研究了几个小时,大概对python中的特殊方法一知半解,现在写写自己的理解,以及记录一些找到的资源.待自己有比较深入理解的时候,再来更新 https://docs.python.org/3/refer ...
- 监控LVS
监控LVS #!/usr/bin/python-2.6.6 #data 2017-10-17 #auth liuchao import commands,os,time #-------------- ...
- .net core(c#)拟合圆测试
说明 很多时候,我们需要运动物体的转弯半径去描述其机器性能.但在大多数的现实条件下,我们只能够获取到运动物体的 GPS 位置点集,并不能直接得到转弯半径或者圆心位置.为此,我们可以利用拟合圆的方式得到 ...
- 全屏滚动插件pagePiling.js
全屏滚动效果是最近非常流行的网页设计形式,带给用户良好的视觉和交互体验.pagePiling.js 这款 jQuery 插件可以帮助前端开发人员轻松实现这种效果.支持所有的主流浏览器,包括IE8+,支 ...
- 5.MySQL数据库操作步骤
第一步:登录到MySQL服务器 第二步:选择当前要操作的数据库 第三步:设置请求和返回数据的字符集 第四步:执行SQL语句 l 增加记录:INSERT INTO news(title,content) ...
- mybatis 源码分析(二)mapper 初始化
mybatis 的初始化还是相对比较复杂,但是作者在初始化过程中使用了多种设计模式,包括建造者.动态代理.策略.外观等,使得代码的逻辑仍然非常清晰,这一点非常值得我们学习: 一.mapper 初始化主 ...
- 彻底搞懂Java中equals和==的区别
java当中的数据类型和“==”的含义: 1.基本数据类型(也称原始数据类型) :byte,short,char,int,long,float,double,boolean.他们之间的比较,应用双等号 ...