博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Poj2186Popular Cows
阅读量:4581 次
发布时间:2019-06-09

本文共 1729 字,大约阅读时间需要 5 分钟。

Popular Cows
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 31533   Accepted: 12817

Description

Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popular. Since popularity is transitive, if A thinks B is popular and B thinks C is popular, then A will also think that C is 
popular, even if this is not explicitly specified by an ordered pair in the input. Your task is to compute the number of cows that are considered popular by every other cow. 

Input

* Line 1: Two space-separated integers, N and M 
* Lines 2..1+M: Two space-separated numbers A and B, meaning that A thinks B is popular. 

Output

* Line 1: A single integer that is the number of cows who are considered popular by every other cow. 

Sample Input

3 31 22 12 3

Sample Output

1

Hint

Cow 3 is the only cow of high popularity. 
 
【题目分析】
  题目大概是有好多牛,牛(们)之间具有某种关系(鬼知道),这种关系具有传递性,如果有 A欢迎B和B欢迎C,那么就有A欢迎C。我们要找到能让其他所有的牛都欢迎的牛。
  (废话真多)
  就是求强连通分量了,然后找到一个强连通分量,缩点,最后找出度为0的点(这里可以自己草纸划一下),如果有多个出度为0的点,那么肯定没有牛被所有牛欢迎,如果只有一个,输出这个点所代表的强连通分量的长度!!!md
#include 
#include
#include
#include
using namespace std;const int maxn=12000;vector
tu[maxn];vector
lt[maxn];int n,m,lts=0;int js=0;int dfn[maxn],low[maxn];int zhan[maxn],top=0;bool isins[maxn];int num[maxn];//num[i]表示i点所在的强连通分量的编号 int d[maxn];void tarjan(int i)//hhhh { int j; dfn[i]=low[i]=++js; isins[i]=1; zhan[top++]=i; for(int j=0;j

 

转载于:https://www.cnblogs.com/xiaoningmeng/p/6071568.html

你可能感兴趣的文章
关于Eclipse的unsupported major minor version 51.0 错误
查看>>
2014年目标
查看>>
weblogic启动后 登陆控制台特别慢的问题
查看>>
Spring加载resource时classpath*:与classpath:的区别
查看>>
映射“DataAdapter.TableMappings”
查看>>
activity生命周期
查看>>
动画学习之Music图形绘制
查看>>
2019 2.15模拟赛
查看>>
基于H5 pushState实现无跳转页面刷新
查看>>
关于同余与模运算的总结
查看>>
js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版
查看>>
【转载】法线贴图Nomal mapping 原理
查看>>
prado 初步分析
查看>>
php 做守护进程1
查看>>
简单员工管理实例
查看>>
SAP 到出XLS
查看>>
HSV
查看>>
JAVA程序中SQL语句无法传递中文参数
查看>>
Android学习_数据库查询使用rawQuery遇到的问题
查看>>
|待研究|委托付款的支付状态触发器
查看>>