传送门: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 缩点模板]的更多相关文章

  1. 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 ...

  2. [USACO06JAN]牛的舞会The Cow Prom Tarjan

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  3. bzoj1654 / P2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 求点数$>1$的强连通分量数,裸的Tanjan模板. #include<iostream> #include&l ...

  4. P2863 [USACO06JAN]牛的舞会The Cow Prom

    洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...

  5. luoguP2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...

  6. 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom

    https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...

  7. 【luogu P2863 [USACO06JAN]牛的舞会The Cow Prom】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2863 求强连通分量大小>自己单个点的 #include <stack> #include ...

  8. LuoGu P2863 [USACO06JAN]牛的舞会The Cow Prom

    题目传送门 这个题还是个缩点的板子题...... 答案就是size大于1的强连通分量的个数 加一个size来统计就好了 #include <iostream> #include <c ...

  9. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom

    传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...

随机推荐

  1. .net core开发从未如此简单,比abp更接地气

    在谈起java一家独大的时候,dotnet人员总是一边嘲笑大量滥竽充数的java从业者,一边羡慕人家的生态.以前是只能羡慕,现在dotnet core开源了,我们都可以为dotnet core的开原生 ...

  2. rocksdb编译步骤——Java、Golang、mac

    如果不是必要不建议自己编译rocksdb,编译的过程比较耗时费力.现在已经有很多编译好的文件可供使用. Java <!-- https://mvnrepository.com/artifact/ ...

  3. 动态开内存(malloc与calloc)

    malloc与calloc 1.函数原型 #include<stdlib.h> void *malloc(unsigned int size);     //申请size字节的内存 voi ...

  4. 【Python】Django【邮箱验证】 后端验证如何生成 token加密验证码 与如何解码!!!!

    1.生成token验证码方案   ,使用itsdangerous    大宝剑, 可以序列化出验证码,并能设置过期时间 安装 itsdangerous pip install itsdangerous ...

  5. JAVA-基础-数据类型转换

    一.类型的转换 java中数据具有类型.这些类型是可以相互进行转换的. 1.自动类型转换 六个和数字相关的基本类型,可以自动由小到大进行类型转换.但是反过来就不行. *注意,在整形自动转浮点型时,有可 ...

  6. JavaSE(一)Java程序的三个基本规则-组织形式,编译运行,命名规则

    一.Java程序的组织形式       Java程序是一种纯粹的面向对象的程序设计语言,因此Java程序必须以类(class)的形式存在,类(class)是Java程序的最小程序单位.       J ...

  7. Windows 纠错

    4:在Windows应用程序中,当需要将窗体显示为模式对话框时,需要调用窗体的()方法.(选择一项)A:Activate()B:ShowDialog()C:Show()D:Close()正确答案是 B ...

  8. c#小灶——数据类型

    C#中有许多数据类型,存储不同的数据要用不同的数据类型.我们这里面向初学只介绍值类型,引用类型和指针类型在后续的学习中会有接触. 整型 int是最常用的整型,用来存储整数.除了int之外,还有其他不常 ...

  9. 直方图均衡基本原理及Python实现

    1. 基本原理 通过一个变换,将输入图像的灰度级转换为`均匀分布`,变换后的灰度级的概率密度函数为 $$P_s(s) = \frac{1}{L-1}$$ 直方图均衡的变换为 $$s = T(r) = ...

  10. centos开发环境安装

    执行 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel ...