//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.4二维并查集",
        "body": [
            "#include<bits/stdc++.h>",
            "using namespace std;",
            "struct T{int x,y;}f[210][210];",
            "int x,y,n,m;char c;T a1,a2;",
            "T s(int x,int y){",
            "    while((x==f[x][y].x)&&(y==f[x][y].y))return f[x][y];",
            "    return s(f[x][y].x,f[x][y].y);",
            "}",
            "int main(){",
            "    scanf(\"%d%d\",&n,&m);",
            "    for(int i=1;i<=n;i++)",
            "        for(int j=1;j<=n;j++)",
            "            f[i][j].x=i,f[i][j].y=j;",
            "    for(int i=1;i<=m;i++)",
            "    {",
            "        cin>>x>>y>>c;",
            "        if(c=='D')a1=s(x,y),a2=s(x+1,y);",
            "        else a1=s(x,y),a2=s(x,y+1);",
            "        if(a1.x==a2.x&&a1.y==a2.y){",
            "            printf(\"%d\\n\",i);return 0;",
            "        }",
            "        else f[a2.x][a2.y]=a1;",
            "    }",
            "    printf(\"draw\");",
            "    return 0;",
            "}",
            ""
        ],
        "description": "插入 格子游戏"
    }
}