//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "并查集": {
        "prefix": "acm-2.4dsu",
        "body": [
            "class DSU {",
            "private:",
            "    vector<int> parent;",
            "    vector<int> rank;",
            "public:",
            "    DSU(int n) {",
            "        parent.resize(n);",
            "        rank.resize(n, 0);",
            "        for (int i = 0; i < n; ++i) {",
            "            parent[i] = i;",
            "        }",
            "    }",
            "    ",
            "    void init(){",
            "        for (int i = 0; i < parent.size(); ++i) {",
            "            parent[i] = i;",
            "        }",
            "    }",
            "",
            "    int find(int x) {",
            "        if (parent[x] != x) {",
            "            parent[x] = find(parent[x]);",
            "        }",
            "        return parent[x];",
            "    }",
            "    ",
            "    void unite(int x, int y) {",
            "        x = find(x);",
            "        y = find(y);",
            "        if (x == y) return;",
            "        ",
            "        if (rank[x] < rank[y]) {",
            "            parent[x] = y;",
            "        } else {",
            "            parent[y] = x;",
            "            if (rank[x] == rank[y]) {",
            "                rank[x]++;",
            "            }",
            "        }",
            "    }",
            "    ",
            "    bool isConnected(int x, int y) {",
            "        return find(x) == find(y);",
            "    }",
            "};"
        ],
        "description": "插入 并查集"
    }
}