题目链接

赤裸裸的板子,就加一个特判就行。直接上代码

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
bool ins[];//记录入没入栈。
bool typ[];//特判*1,是强连通分量就直接过了。
int top;int ans[];
int stack[];//手写栈。
void push(int x)//手写栈ing.
{
ins[x]=true;
stack[++top]=x;
return ;
}
void pop()
{
ins[stack[top]]=false;
top--;
return ;
}
struct data{
int v;int next;
}edge[];
int cnt;int alist[];
void add(int u,int v)//继续手写结构体。
{
edge[++cnt].v=v;
edge[cnt].next=alist[u];
alist[u]=cnt;
}
int dfn[];int dfu;//dfn作为x的入栈序号。
int low[];int res=;
void dfs(int x)//dfs
{
dfn[x]=++dfu;//记录搜索序号
push (x);
low[x]=dfn[x];
int next=alist[x];
while(next)
{
int v=edge[next].v;
if(ins[v]==true)//被搜过就不用再搜了
{
low[x]=min(low[x],low[v]);
}
else if(ins[v]==false)
{
dfs(v);
low[x]=min(low[x],low[v]);
}
next=edge[next].next;
}
if(dfn[x]==low[x])//如果搜回来了。
{
while(low[stack[top]]==low[x])
{
typ[stack[top]]=true;
pop();
ans[x]++;
}
if(ans[x]>) res++;//想要转圈的话必须要两个人及以上。
}
return;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int n1,m1;
scanf("%d%d",&n1,&m1);//不解释。
add(n1,m1);
}
for(int i=;i<=n;i++)
{
if(typ[i]==) continue;//要是在扫过的强连通分量里面直接过。
else dfs(i);
}
printf("%d",res);
return ;//程序拜拜
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. python's fourteenth day for me 内置函数

    locals:  函数会以字典的类型返回当前位置的全部局部变量. globals:  函数会以字典的了类型返回全部的全局变量. a = def func(): b = print(locals()) ...

  2. java成神之——接口,泛型,类

    接口 接口定义 默认方法 函数式接口 泛型 泛型类 泛型类继承 类型限定 泛型方法 泛型接口 类 构造函数 类的继承 抽象类 instanceof运算符 内部类 equals 结语 接口 接口定义 j ...

  3. java - 只输出中文,(不包含标点)

    String a ="12dss显示,‘:()中文只"; StringBuffer b = new StringBuffer(); for(int i = 0;i<a.len ...

  4. .gitignore non-valiate

    Git忽略规则及.gitignore规则不生效的解决办法 分享到:更多19 2015-02-12    分类:Share2人评论65,215 次人浏览 在git中如果想忽略掉某个文件,不让这个文件提交 ...

  5. fgets、gets和scanf的区别

    gets()从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在buffer指针所指向的字符数组中.换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字 ...

  6. History - BOM对象

    History 对象 History 对象包含用户(在浏览器窗口中)访问过的 URL. History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问. 注 ...

  7. codeforce452DIV2——F. Letters Removing

    题意:给一个字符串和m个操作,每次给出l,r,c,把字符串中l-r这段区间的字符为c的字符删掉,求最后的字符串.(n,m<=2e5)线段树.注意这个区间修改和普通区间修改的区别. 他们都是用树状 ...

  8. selenium3加载浏览器

    浏览器禁用更新: 因为selenium对浏览器的支持是有限制的.当浏览器更新到最新版本时,需要下载支持最新版本的插件.有时候selenium还没有更新到支持最新版本的插件,但本地已经更新到最新版本了. ...

  9. os.chdir("/deepmatching") OSError: [Errno 2] No such file or directory: '/deepmatching'

    #os.chdir("/deepmatching")os.chdir(os.path.dirname(os.path.abspath("deepmatching1&quo ...

  10. CAP理论与HBase

    The short summary of the article is that CAP isn't "C, A, or P, choose two," but rather &q ...