洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
ng the other ends of her ropes (if she has any), along with the cows holding the other ends of any ropes they hold, etc. When Bessie dances clockwise around the tank, she must instantly pull all the other cows in her group around clockwise, too. Likewise,
if she dances the other way, she must instantly pull the entire group counterclockwise (anti-clockwise in British English).
Of course, if the ropes are not properly distributed then a set of cows might not form a proper dance group and thus can not succeed at the Round Dance. One way this happens is when only one rope connects two cows. One cow could pull the other in one direction, but could not pull the other direction (since pushing ropes is well-known to be fruitless). Note that the cows must Dance in lock-step: a dangling cow (perhaps with just one rope) that is eventually pulled along disqualifies a group from properly performing the Round Dance since she is not immediately pulled into lockstep with the rest.
Given the ropes and their distribution to cows, how many groups of cows can properly perform the Round Dance? Note that a set of ropes and cows might wrap many …
输入输出格式
输入格式:
Line 1: Two space-separated integers: N and M
Lines 2..M+1: Each line contains two space-separated integers A and B that describe a rope from cow A to cow B in the clockwise direction.
输出格式:
Line 1: A single line with a single integer that is the number of groups successfully dancing the Round Dance.
输入输出样例
输入样例#1:
5 4
2 4
3 5
1 2
4 1
输出样例#1:
1
说明
Explanation of the sample:
ASCII art for Round Dancing is challenging. Nevertheless, here is a representation of the cows around the stock tank:
_1___
/****
5 /****** 2
/ /**TANK**|
********/
******/ 3
4____/ /
_______/
Cows 1, 2, and 4 are properly connected and form a complete Round Dance group. Cows 3 and 5 don't have the second rope they'd need to be able to pull both ways, thus they can not properly perform the Round Dance.
强联通分量的裸题
直接输出强联通分量的个数就好
1 #include<cstdio>
2 #include<cstring>
3 #include<stack>
4 #include<queue>
5 #include<map>
6 #include<stack>
7 #define ls k<<1
8 #define rs k<<1|1
9 #define LL long long
10 using namespace std;
11 const int MAXN=100002;
12 inline int read()
13 {
14 char c=getchar();int x=0,flag=1;
15 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();}
16 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag;
17 }
18 struct node
19 {
20 int u,v,nxt;
21 }edge[MAXN];
22 int head[MAXN];
23 int num=1;
24 inline void add_edge(int x,int y)
25 {
26 edge[num].u=x;
27 edge[num].v=y;
28 edge[num].nxt=head[x];
29 head[x]=num++;
30 }
31 int low[MAXN];
32 int dfn[MAXN];//时间戳
33 int tot=0;
34 stack<int>s;
35 int ans=0;
36 int vis[MAXN];
37 int color[MAXN],colornum=0;
38 int happen[MAXN];
39 inline void Tarjan(int node)
40 {
41 low[node]=dfn[node]=++tot;
42 vis[node]=1;
43 s.push(node);
44 for(int i=head[node];i!=-1;i=edge[i].nxt)
45 {
46 if(!dfn[edge[i].v])
47 Tarjan(edge[i].v),low[node]=min(low[node],low[edge[i].v]);
48 else if(vis[edge[i].v])
49 low[node]=min(low[node],dfn[edge[i].v]);
50 }
51 if(dfn[node]==low[node])
52 {
53 colornum++;
54 int h;
55 do
56 {
57 h=s.top();
58 if(color[s.top()]==0) color[s.top()]=colornum;
59 vis[s.top()]=0;
60 s.pop();
61 }while(node!=h);
62 }
63 }
64 int main()
65 {
66 memset(head,-1,sizeof(head));
67 int n=read(),m=read();
68 for(int i=1;i<=m;i++)
69 {
70 int x=read(),y=read();
71 add_edge(x,y);
72 }
73 for(int i=1;i<=n;i++)
74 if(color[i]==0)
75 Tarjan(i);
76 for(int i=1;i<=n;i++)
77 happen[color[i]]++;
78 int ans=0;
79 for(int i=1;i<=colornum;i++)
80 if(happen[i]>1)
81 ans++;
82 printf("%d",ans);
83 return 0;
84 }
- 海量数据迁移之冲突数据筛查(r2 第1天)
- sqlldr加载性能问题的排查 (r2第2天)
- sqlplus无法启动的问题及解决(3) (25天)
- sqlplus无法启动的问题及解决(2) (25天)
- 10g升级至11g exp的问题解决(23天)
- redo日志文件学习(22天)
- 数据库文件的迁移
- excel文件内容导入数据库的问题及解决(20天)
- 10g,11g数据泵的导入问题及解决(19天)
- ORACLE 11g导入9i dump的问题及解决
- 服务器增加内存后无法重启数据库的问题及解决 (36天)
- 分区表放入keep pool,recycle pool的问题及解析(34天)
- 临时表空间故障处理 (33天)
- 关于物化视图疑问(32天)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法