洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
来源:互联网 发布:仿手机淘宝 源码 编辑:程序博客网 时间:2024/05/20 21:23
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: 复制
输出样例#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
2 #include
3 #include
4 #include
5 #include
6 #include
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 stacks;
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 }
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
- [USACO06JAN]牛的舞会The Cow Prom
- 【题解】[USACO06JAN]牛的舞会The Cow Prom(tarjan)
- 【luogu 2863】[USACO06JAN]牛的舞会The Cow Prom题目描述
- Tarjan缩点——牛的舞会The Cow Prom
- bzoj1654[The Cow Prom 奶牛舞会] tarjan求有向无环图的强联通分量
- BZOJ 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
- bzoj1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- [BZOJ1654] [Usaco2006 Jan]The Cow Prom 奶牛舞会
- poj 3180 The Cow Prom(奶牛舞会)
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- BZOJ 1635: [Usaco2006 Jan]The Cow Prom 奶牛舞会 tarjan
- 【bzoj1654】[Usaco2006 Jan]The Cow Prom 奶牛舞会
- 【POJ3180】The Cow Prom奶牛舞会 还是一道挺裸的有向图强连通分量
- POJ3180-The Cow Prom
- |BZOJ 1654|强连通分量|[Usaco2006 Jan]The Cow Prom 奶牛舞会
- js函数预处理
- 火车出站小结
- 购物车 数量,总价,删除
- 程序员之1024
- 第八周项目3对称矩阵压缩存储的实现与应用(1)
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
- python 的继承
- Java 小结
- mysql学习笔记1
- Java开源-astar:A 星算法
- HttpUtil
- MFC两个以上DockPane重叠的方法
- php 语法检验
- Api