Popular Cows(codevs 2186)】的更多相关文章

题意: 有N(N<=10000)头牛,每头牛都想成为most poluler的牛,给出M(M<=50000)个关系,如(1,2)代表1欢迎2,关系可以传递,但是不可以相互,即1欢迎2不代表2欢迎1,但是如果2也欢迎3那么1也欢迎3.给出N,M和M个欢迎关系,求被所有牛都欢迎的牛的数量. /* tarjan缩点后,统计每个所点的出度,当有且只有一个出度为0的缩点是, 答案即为这个缩点所包含的点的数量,否则答案为0 */ #include<cstdio> #include<ios…
                                                              Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30999   Accepted: 12580 Description Every cow's dream is to become the most popular cow in the herd. In a herd of…
原题如下: Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 40746   Accepted: 16574 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 <…
http://poj.org/problem?id=2186 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 co…
http://poj.org/problem?id=2186 题意 :给你n头牛,m对关系,每对关系由两个编号组成,u和v代表着u认为v是受欢迎的,如果1认为2是受欢迎的,2认为3是受欢迎的,那1认为3也是受欢迎的. 思路 :强联通分量的Tarjan做法,将这些牛之间的关系看成一个有向图,最受欢迎的那个牛的那个点一定是出度为0的点.Tarjan的基本资料:http://hi.baidu.com/lydrainbowcat/item/1c664b662b1a1692c4d2491c #includ…
强连通缩点,统计入度为1的缩点后的点的个数 个数1的话输出这个强连通分量的点的数量 否则输出0: code /* Kosaraju算法,无向图的强连通分量,时间复杂度O(n+m) 思路: 按照图G的深度遍历序列,在G的反图上进行深搜 能够搜到的点集就是一个强联通分量 */ #include <iostream> #include <cstring> using namespace std; const int INF = 10009; //链接表,偶数边为原图,奇数边为反图 str…
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 pop…
崇拜有传递性.求所有牛都崇拜的牛tarjan算法求强连通. 如果不连通就不存在.如果联通,缩点后唯一一个出度为零的点就是答案,有多个则不存在. #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #i…
id=2186">[2186]Popular Cows(强联通分支及其缩点) Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28323   Accepted: 11459 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 1…
传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 12921 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 <=…