BZOJ 1051: [HAOI2006]受欢迎的牛 缩点
1051: [HAOI2006]受欢迎的牛
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=1051
Description
⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.
⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.
There are three types of players.
Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.
There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.
Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.
The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?
Input
第一行两个数N,M。 接下来M行,每行两个数A,B,意思是A认为B是受欢迎的(给出的信息有可能重复,即有可能出现多个A,B)
Output
一个数,即有多少头牛被所有的牛认为是受欢迎的。
Sample Input
3 3
1 2
2 1
2 3
Sample Output
1
HINT
题意
题解:
缩点,然后看出度为0 的点是否只有一个,如果只有一个就输出这个点的大小
否则就是0
代码
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cstring>
using namespace std;
#define maxn 10005
vector<int> E[maxn];
vector<int> rE[maxn];
int belong[maxn];
int vis[maxn];
int cl[maxn];
int cnt = ;
int siz[maxn];
int kis[maxn];
void dfs1(int x)
{
vis[x]=;
for(int i=;i<E[x].size();i++)
{
int e = E[x][i];
if(vis[e])continue;
dfs1(e);
}
cl[++cnt]=x;
}
void dfs2(int x)
{
vis[x]=;
belong[x]=cnt;
siz[cnt]++;
for(int i=;i<rE[x].size();i++)
{
int e = rE[x][i];
if(vis[e])continue;
dfs2(e);
}
}
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
{
int x,y;scanf("%d%d",&x,&y);
E[x].push_back(y);
rE[y].push_back(x);
}
for(int i=;i<=n;i++)
{
if(!vis[i])
dfs1(i);
}
memset(vis,,sizeof(vis));
cnt = ;
for(int i=n;i>=;i--)
{
if(!vis[cl[i]])
{
cnt++;
dfs2(cl[i]);
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<E[i].size();j++)
{
if(belong[i]==belong[E[i][j]])
continue;
kis[belong[i]]++;
}
}
int ans1=,ans2=;
for(int i=;i<=cnt;i++)
{
if(kis[i]==)
{
ans1++;
ans2=i;
}
}
if(ans1==)
printf("%d\n",siz[ans2]);
else
puts("");
}
BZOJ 1051: [HAOI2006]受欢迎的牛 缩点的更多相关文章
- bzoj 1051: [HAOI2006]受欢迎的牛 tarjan缩点
1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2092 Solved: 1096[Submit][Sta ...
- BZOJ 1051: [HAOI2006]受欢迎的牛( tarjan )
tarjan缩点后, 有且仅有一个出度为0的强连通分量即answer, 否则无解 ----------------------------------------------------------- ...
- BZOJ 1051: [HAOI2006]受欢迎的牛(SCC)
1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 8172 Solved: 4470[Submit][Sta ...
- BZOJ 1051: [HAOI2006]受欢迎的牛 强连通缩点
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1051 题解: 强连通缩点得到DAG图,将图转置一下,对入度为零的点跑dfs看看能不能访问 ...
- bzoj 1051: [HAOI2006]受欢迎的牛 (Tarjan 缩点)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1051 思路: 首先用Tarjan把环缩成点,要想收到所有人的欢迎,那么这个点的出度必为0,且 ...
- bzoj 1051 [HAOI2006]受欢迎的牛(tarjan缩点)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1051 题解:缩点之后判断出度为0的有几个,只有一个那么输出那个强连通块的点数,否者 ...
- 洛谷 P2341 BZOJ 1051 [HAOI2006]受欢迎的牛
题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之间的“喜欢”是可以传递的——如果A喜 欢B,B喜欢C,那么A也喜欢C ...
- BZOJ 1051: [HAOI2006]受欢迎的牛
Description 一个有向图,求所以能被别的点到达的点的个数. Sol Tarjan + 强连通分量 + 缩点. 缩点以后找强连通分量,缩点,然后当图有且仅有1个出度为1的点时,有答案. Cod ...
- 【BZOJ 1051】 1051: [HAOI2006]受欢迎的牛 (SCC)
1051: [HAOI2006]受欢迎的牛 Description 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如 ...
随机推荐
- 《C++ Primer 4th》读书笔记 第8章-标准IO库
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936457.html
- 如何获取数据块结构信息dump
有个pub_department的表,索引为PK_PUB_DEPARTMENT. 1.找到object_id select object_id from dba_objects s where ...
- HDU 4422 The Little Girl who Picks Mushrooms
题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...
- ajax-Ajax试题
ylbtech-doc:ajax-Ajax试题 Ajax 1.A,Ajax试题返回顶部 001.{Ajax题目}使用Ajax可带来便捷有()(选择3项) A)减轻服务器的负担 B) ...
- C++重要知识点小结---1
1.C++中类与结构的唯一区别是:类(class)定义中默认情况下的成员是private的,而结构(struct)定义中默认情况下的成员是public的. 2. ::叫作用域区分符,指明一个函数属于哪 ...
- [BILL WEI] stimulsoft 分组页眉页脚的使用
我们在通过stimulsoft设计报表的时候,有的时候,需要做出如下图报表样式 这个时候,因为箱号是分开扩展的,我们就需要用到分组页眉了,如下图demo跟实例所示:
- PICT实现组合测试用例(一)
最近阅读了史亮老师的<软件测试实战:微软技术专家经验总结>一书,其中“测试建模”一章让我受益匪浅.想想以前的测试有多久没有花过心思放在测试用例的设计上了,一直强调“测试思想”的培养也都只是 ...
- 《Python 学习手册4th》 第六章 动态类型简介
''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书)“重点笔 ...
- mysql EF
使用 mysql-installer-community-5.6.26.0.msi visual studio 2013 update 4版 Install-Package EntityFramewo ...
- 在DataTable 中增加一列
//在这里需要增加一个列. DataColumn column = dt.Columns.Add("行号", Type.GetType("S ...