
并查集
文章平均质量分 90
DT2131
Rage, rage against the dying of the light.Do not go gentle into that good night.
展开
-
CodeForces - 744A Hongcow Builds A Nation (并查集+容斥)
题意: 给出一个无向图,有N个点,M个边和K个根节点。问在保证根节点间无通路时,最多加多少条边。 思路: 利用并查集计算出每个根对应的集合中点的个数后,显然我们有三种点集: 1.点数最多的有根点集 2.其他有根点集 3.无根点集 满足以上条件原创 2016-12-29 18:48:53 · 627 阅读 · 0 评论 -
CodeForces - 791B Bear and Friendship Condition
题意: 给你m对朋友关系,如果x-y是朋友,y-z是朋友,要求x-z也是朋友. 问你所给的图是否符合。 思路: 题意简单明了,就是判图中点与点的关系是否都是团。可以直接建图搜一圈。 也可以用并查集,参考:http://blog.youkuaiyun.com/harlow_cheng/article/details/63519393 搜索思路代码: #include using namespac原创 2017-03-20 12:23:42 · 437 阅读 · 0 评论