poj 2186 强连通分量
生活随笔
收集整理的這篇文章主要介紹了
poj 2186 强连通分量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
poj 2186 強連通分量
傳送門
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 33414 Accepted: 13612 DescriptionEvery 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 Input3 3 1 2 2 1 2 3 Sample Output1 HintCow 3 is the only cow of high popularity.我們可以將一個強聯通分量看成一個點進行處理,因為這個強連通分量中的點都是相互可達的,那么只要其中一頭牛成為紅人,那么其他牛也是一樣的,同時我們可以得到兩個結論
所以我們只需要求出那個強連通分量,最終再反向dfs驗證是否可達每個點,這題就解出來了。
轉載于:https://www.cnblogs.com/zsyacm666666/p/6807398.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的poj 2186 强连通分量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Bootstrap css3
- 下一篇: 搜索引擎优化网页设计:最佳实践