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)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别 上鲜花,她们要表演圆舞.
只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的水池.奶牛们围在池边站好, 顺时针顺序由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;
}
USACO 06JAN 牛的舞会 洛谷2863的更多相关文章
- 洛谷2863 [Usaco06JAN]牛的舞会
题目描述 约翰的N (2 <= N <= 10,000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别 上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一 ...
- 【树形dp入门】没有上司的舞会 @洛谷P1352
传送门 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.现在有个周年庆宴会,宴会每邀请来一个职员都会增加一定的快乐指 ...
- 洛谷P1519 穿越栅栏 Overfencing
P1519 穿越栅栏 Overfencing 69通过 275提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 USACO是100分,洛谷是20分 为什么 ...
- 洛谷 P1219 八皇后【经典DFS,温习搜索】
P1219 八皇后 题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序 ...
- 洛谷P1219 :八皇后(DFS+回溯)
题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...
- 洛谷P1219 八皇后【dfs】
题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...
- P1219 八皇后 洛谷
题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...
- 洛谷 P1219 八皇后题解
题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...
- 【洛谷P1219 八皇后】
参考思路见白书(一本通) 题目链接 题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上 ...
随机推荐
- PHP水仙花数的实现
php水仙花数是什么? 水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身.(例如:1^3 + 5^3 + 3^3 = 153)三位的水仙花数共有4个:153,3 ...
- mysql查找字段空、不为空的方法总结
1.不为空 Select * From table_name Where id<>'' Select * From table_name Where id!='' 2.为空 Select ...
- Python排序功能进阶
sorted和sort() li = [9, 1, 8, 2, 7, 3, 6, 4, 5] s_li = sorted(li) print ('Sorted Variable: \t', s_li) ...
- Java中Map集合的基本功能
Map基本方法: put方法: remove方法: isEmpty方法: . clear方法: containsKey方法: containsValue方法 size方法: get方法: keySet ...
- python对具有宏excel的操作
一.使用win32com库 安装pip install pypiwin32 import win32com.client #excel xlApp =win32com.client.DispatchE ...
- 合并vector里的内容,输出一个string
string merge_vector(vector<string> dp_scpe_all) { //合并vector里的内容 string new_dp_scpe; ; m < ...
- readUTF()和writeUTF()
readUTF()和writeUTF() 这是dataOutputStream 的方法~~使用utf-8编码 其实就是从unicode变过来的,utf8编码把unicode的ASCII编码变成1个字节 ...
- 23、css的定位问题
1.positon:relative相对定位 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...
- VirtualBox的源码学习
VMM重要的组件 TRPM (Trap Manager) PGM (Page Manager) REM (Recompiled Execution Manager) EM (Execution Man ...
- SQlite 学习资料
很有用的开源跨平台数据库,可以作为客户端的小型内存数据库使用,据说它有N多用户(Nokia's Symbian,Mozilla,Abobe,Google,阿里旺旺,飞信,Chrome,FireFo ...