日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

USACO 06JAN 牛的舞会 洛谷2863

發(fā)布時(shí)間:2023/12/18 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USACO 06JAN 牛的舞会 洛谷2863 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目描述

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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。