USACO 06JAN 牛的舞会 洛谷2863
題目描述
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)只奶牛非常興奮,因?yàn)檫@是舞會(huì)之夜!她們穿上禮服和新鞋子,別 上鮮花,她們要表演圓舞.
只有奶牛才能表演這種圓舞.圓舞需要一些繩索和一個(gè)圓形的水池.奶牛們圍在池邊站好, 順時(shí)針順序由1到N編號(hào).每只奶牛都面對(duì)水池,這樣她就能看到其他的每一只奶牛.
為了跳這種圓舞,她們找了 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; }轉(zhuǎn)載于:https://www.cnblogs.com/sdfzsyq/p/9677135.html
總結(jié)
以上是生活随笔為你收集整理的USACO 06JAN 牛的舞会 洛谷2863的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JS判断请求来自Android手机还是i
- 下一篇: 关于今天写Flex视频循环播放所出现的s