题目链接:https://www.luogu.org/problemnew/show/P2863

求强连通分量大小>自己单个点的

#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 10;
struct edge{
int next, to, from, len;
}e[maxn<<2];
int head[maxn], cnt;
int n, m, color[maxn], tong[maxn], num, tim, ans;
int dfn[maxn], low[maxn];
bool vis[maxn];
stack<int> s;
void add(int u, int v)
{
e[++cnt].from = u;
e[cnt].to = v;
e[cnt].next = head[u];
head[u] = cnt;
}
void tarjan(int x)
{
dfn[x] = low[x] = ++tim;
s.push(x); vis[x] = 1;
for(int i = head[x]; i != -1; i = e[i].next)
{
int v = e[i].to;
if(!dfn[v])
{
tarjan(v);
low[x] = min(low[x], low[v]);
}
else if(vis[v])
{
low[x] = min(low[x], low[v]);
}
}
if(dfn[x] == low[x])
{
color[x] = ++num;
vis[x] = 0;
while(s.top() != x)
{
color[s.top()] = num;
vis[s.top()] = 0;
s.pop();
}
s.pop();
}
}
int main()
{
memset(head, -1, sizeof(head));
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; i++)
{
int u, v;
scanf("%d%d",&u,&v);
add(u,v);
}
for(int i = 1; i <= n; i++)
if(!dfn[i]) tarjan(i);
for(int i = 1; i <= n; i++)
tong[color[i]]++;
for(int i = 1; i <= n; i++)
if(tong[i] > 1) ans++;
printf("%d",ans);
return 0;
}

【luogu P2863 [USACO06JAN]牛的舞会The Cow Prom】 题解的更多相关文章

  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. LuoGu P2863 [USACO06JAN]牛的舞会The Cow Prom

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

  3. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom 题解

    每日一题 day11 打卡 Analysis 好久没大Tarjan了,练习练习模板. 只要在Tarjan后扫一遍si数组看是否大于1就好了. #include<iostream> #inc ...

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

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

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

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

  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. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom

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

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

    代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...

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

    一道tarjan的模板水题 在这里还是着重解释一下tarjan的代码 #include<iostream> #include<cstdio> #include<algor ...

随机推荐

  1. Java for循环的几种用法分析

    J2SE 1.5提供了另一种形式的for循环.借助这种形式的for循环,可以用更简单地方式来遍历数组和Collection等类型的对象.本文介绍使用这种循环的具体方式,说明如何自行定义能被这样遍历的类 ...

  2. zookeeper JAVA API 简单操作

    package org.admln.program.Zoo_Test; import java.io.IOException; import java.security.NoSuchAlgorithm ...

  3. MySQL查询长数据是无值返回(可以尝试换行符)

    如,要在数据库中包含这样数据的记录有多少条: <table class="link-more-blue" style="width: 100%;" bor ...

  4. Mavne 打包时出现程序包找到不的问题

    <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactI ...

  5. topN问题

    topN问题:给出一个数组,找出前N个最大的元素. topN问题可以用分治法解决,这个问题与快速排序类似,快速排序是用一个数对数组进行划分,topN问题则不需完成排序,只需划分出前n个最大的数字即可. ...

  6. K&R C风格函数

    前些天在看getopt源码, 一种前所未见的函数定义方法 int getopt(nargc, nargv, ostr) int nargc; char * const nargv[]; const c ...

  7. 信鸽推送 C#版SDK

    信鸽官方sdk没提供C#版的DEMO,考虑到应该有其他.NET的也会用到信鸽,下面是我在使用信鸽过程中写的demo.有什么不对的地方,欢迎各位大牛指导. 使用过程中主要是有2个问题: 1.参数组装,本 ...

  8. HDU 1003 最大连续和

    http://www.acmerblog.com/hdu-1003-Max-Sum-1258.html 这里难点只有求起始位置,把握状态变化就行.一般这种子序列问题,都可以用dp简化 #include ...

  9. WinSock 重叠IO模型

    title: WinSock 重叠IO模型 tags: [WinSock 模型, 网络编程, 重叠IO模型] date: 2018-06-29 20:26:13 categories: Windows ...

  10. SQL:Example Uses of the SUBSTRING String Function

    ---Example Uses of the SUBSTRING String Function --http://www.sql-server-helper.com/tips/tip-of-the- ...