
并查集
ChasingTheFreeWind
这个作者很懒,什么都没留下…
展开
-
leetcode每日一题 990. 等式方程的可满足性(并查集)
class Solution { public: map<int,int> father; int Find(int x) { int r = x; while(father[r]!=r) r = father[r]; int i = x; int j; while(father[i]!=i) { j = father[i]; .原创 2020-06-08 11:21:20 · 144 阅读 · 0 评论 -
leetcode每日一题 128.最长连续序列(并查集)
并查集 思路 并查集,遍历数组,如果该数字+1在数组中则将它们合并。 代码 class Solution { unordered_map<int,int> father,cnt; int Find(int x) { int r = x; while(r!=father[r]) { r = father[r]; } int i = x; int j; .原创 2020-06-06 12:18:00 · 163 阅读 · 0 评论 -
1118 Birds in Forest (25分) (并查集)
简单题,写出并查集就完事。 #include <iostream> #include <cstring> #include <cstdio> #include <set> #define MAX 10100 using namespace std; int N,Q; int father[MAX]; set<int> birds; in...原创 2020-05-02 12:39:08 · 190 阅读 · 0 评论