摘要: 并查集(Disjoint Set Union)模板 #include <vector> using namespace std; /** * Disjoint Set Union */ class DSU { vector<int> s; int cnt; // 记录集合个数 public: DSU 阅读全文
posted @ 2021-03-01 15:56 Zewbie 阅读(36) 评论(0) 推荐(0)
摘要: POJ - 1611The Suspects 并查集。 将每个组的学生进行合并,最后 \(0\) 号学生所在集合的学生个数即为答案。 #include <cstdio> #include <vector> using namespace std; /** * Disjoint Set Union * 阅读全文
posted @ 2021-03-01 15:44 Zewbie 阅读(45) 评论(0) 推荐(0)
摘要: POJ - 2236Wireless Network 并查集。 每次修理计算机,遍历可以与之相连的计算机并进行合并。时间复杂度 \(O(n\log n)\) 。最多只用修理 \(n\) 次。 每次测试连通性,判断根节点是否相同,时间复杂度 \(O(1)\) 。最多不过 \(3e5\) 次测试。 总时 阅读全文
posted @ 2021-03-01 15:15 Zewbie 阅读(68) 评论(0) 推荐(0)