题目描述

The N (2 <= N <= 10,000) cows are so excited: it’s prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance.

Only cows can perform the Round Dance which requires a set of ropes and a circular stock tank. To begin, the cows line up around a circular stock tank and number themselves in clockwise order consecutively from 1..N. Each cow faces the tank so she can see the other dancers.

They then acquire a total of M (2 <= M <= 50,000) ropes all of which are distributed to the cows who hold them in their hooves. Each cow hopes to be given one or more ropes to hold in both her left and right hooves; some cows might be disappointed.

约翰的N (2 <= N <= 10,000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别 上鲜花,她们要表演圆舞.

只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的水池.奶牛们围在池边站好, 顺时针顺序由1到N编号.每只奶牛都面对水池,这样她就能看到其他的每一只奶牛.

为了跳这种圆舞,她们找了 M(2

#include<iostream>
#include<cstdio>using namespace std;
const int MAXN = 10005;struct Edge{int nxt,to;
}edge[MAXN*5];int n,m,head[MAXN],low[MAXN],dfn[MAXN];
int cnt,num,ans,top,stack[MAXN];
bool vis[MAXN];inline void add(int bg,int ed){edge[++cnt].to=ed;edge[cnt].nxt=head[bg];head[bg]=cnt;
}inline void tarjan(int u){vis[u]=1;stack[++top]=u;dfn[u]=low[u]=++num;for(int i=head[u];i;i=edge[i].nxt){int v=edge[i].to;if(!dfn[v]){tarjan(v);low[u]=min(low[u],low[v]); }else if(vis[v])low[u]=min(low[u],dfn[v]); }if(low[u]==dfn[u]){if(stack[top]!=u)ans++;vis[u]=0;while(stack[top]!=u){vis[stack[top]]=0;top--;}top--;}
}int main(){scanf("%d%d",&n,&m);for(register int i=1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);add(x,y);}for(register int i=1;i<=n;i++)if(!dfn[i]) tarjan(i);printf("%d",ans);return 0;
}

转载于:https://www.cnblogs.com/sdfzsyq/p/9677135.html

USACO 06JAN 牛的舞会 洛谷2863相关推荐

  1. 信息学奥赛一本通 1343:【例4-2】牛的旅行 | 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours

    [题目链接] ybt 1343:[例4-2]牛的旅行 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours [题目考点] 1. 图论 最短路径 Floyd算法 Floyd算法时间复杂度 ...

  2. 【洛谷 2863】牛的舞会

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

  3. layui树形父子不关联_DP专题7 | 没有上司的舞会 洛谷1352(树形DP)

    高能预警:这是一篇超过5分钟的学习文章,暑假了可以多学会 本篇继续咱们的DP专题,树形DP入门.动态规划每一个类型的DP都是深坑,期望童鞋们自己在这个系列的基础上多花时间进行拓展,学习愉快~ 在讨论树 ...

  4. 洛谷 P1219 八皇后

    P1219 八皇后 题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序 ...

  5. 洛谷——P1219 八皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  6. 洛谷 P1219 八皇后题解

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  7. 洛谷 P1219 ---- 八皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  8. 洛谷 P1219八皇后

    题目: 题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子.上面的布局可以用序列2 4 6 ...

  9. 洛谷、牛客网、AcWing 刷题(python版)

    牛客网python专项练习整理(一) https://blog.csdn.net/weixin_41913008/article/details/87203468 牛客网剑指offer--python ...

最新文章

  1. Django入门:DoesNotExist: User matching query does not exist.
  2. Meaningless Sequence Gym - 102832D
  3. 每日一题 Day8:CodeForces-996A.Hit the Lottery(贪心)
  4. 二分查找算法java
  5. 手把手教你创建容器服务Kubernetes集群
  6. JGG:青岛大学苏晓泉团队利用条件致病菌指数评估环境微生物风
  7. 串口接收到的浮点数(解码后出现的错误)
  8. 理解纯CSS画三角形
  9. 【离散数学】单向连通和弱连通的区别
  10. POJ1007 UVA612 UVALive5414 ZOJ1188 HDU1379 Bailian4086 DNA Sorting【排序+逆序数】
  11. HDU2553 N皇后问题【DFS+回溯法】
  12. 建立账套时,没有选择客户分类档案
  13. ptime在SIP中的应用
  14. paip.提升效率---模块化设计方法V2012.9.15
  15. exe msdt 无法上网_msdt(缺失msdtexe连不上网)
  16. Exploring Plain Vision Transformer Backbones for Object Detection.
  17. c语言角度转换为弧度程序,C语言之将弧度值转换为角度值
  18. 用python写1加到100怎么写_python计算1到100的和
  19. ads1115多片并联
  20. STM32F091不识别仿真器的案例

热门文章

  1. C++ 异常,标准异常类,自定义异常类,throw,try,catch语句
  2. 【HDU - 6558】The Moon(期望dp)
  3. *【牛客 - 315D】打车(贪心,同优则立证明法)
  4. *【HDU - 1042 】 N! (大数乘法)
  5. eclipse提示方法已过时_提高效率,eclipse上你可能不知道的技巧
  6. leetcode551. 学生出勤记录 I
  7. 一元多项式的表示和相加【数据结构】
  8. Python模块(3)--PIL 简易使用教程
  9. STL 源码剖析 空间配置器
  10. 以太坊私有链 使用dev模式