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

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

Popular Cows
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 29799   Accepted: 12090

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.

Source

tarjan模板
#include
#include
#include
#include
#include
using namespace std;#define N 10010vector
grap[N];//稀疏图,用邻接表表示图stack
s;//栈 int low[N];//low[u] 为u或u的子树能够追溯到的最早的栈中节点的次序编号 int dfn[N];//dfn[u] 为u搜索的次序编号(时间戳) int mark[N];//标记是否在栈中 int id[N];//id[i] = j 表示原图的点i缩点后为点j int pd;//顶点的前序编号int sd;//记录总共将图缩成多少个点 int sum[N];//记录sd编号的有几个点缩成 void tarjan(int v){ low[v]=dfn[v]=++pd; s.push(v); mark[v]=1; for(int i=0;i

 

转载于:https://www.cnblogs.com/shenben/p/5633373.html

你可能感兴趣的文章
java中相同名字不同返回类型的方法
查看>>
Rails NameError uninitialized constant class solution
查看>>
Android 获取SDCard中某个目录下图片
查看>>
设置cookies第二天0点过期
查看>>
【转载】NIO客户端序列图
查看>>
poj_2709 贪心算法
查看>>
【程序员眼中的统计学(11)】卡方分布的应用
查看>>
文件夹工具类 - FolderUtils
查看>>
http://blog.csdn.net/huang_xw/article/details/7090173
查看>>
lua学习例子
查看>>
研究:印度气候变暖速度加剧 2040年或面临重灾
查看>>
python爬虫——爬取豆瓣TOP250电影
查看>>
C++与Rust操作裸指针的比较
查看>>
了解webpack-4.0版本(一)
查看>>
如何培养良好的编程风格
查看>>
Netty Channel源码分析
查看>>
基于 HTML5 WebGL 的 3D 机房
查看>>
Java编程——数据库两大神器:索引和锁
查看>>
springMvc学习笔记(2)
查看>>
吐槽Javascript系列二:数组中的splice和slice方法
查看>>