{"problem":{"name":"Tying Rope","description":{"content":"There are $N$ ropes numbered $1$ through $N$. One end of each rope is painted red, and the other is painted blue. You are going to perform $M$ operations of tying ropes. In the $i$\\-th operation, you ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc293_d"},"statements":[{"statement_type":"Markdown","content":"There are $N$ ropes numbered $1$ through $N$. One end of each rope is painted red, and the other is painted blue.\nYou are going to perform $M$ operations of tying ropes. In the $i$\\-th operation, you tie the end of rope $A_i$ painted $B_i$ with the end of rope $C_i$ painted $D_i$, where `R` means red and `B` means blue. For each rope, an end with the same color is not tied multiple times.\nFind the number of groups of connected ropes that form cycles, and the number of those that do not, after all the operations.\nHere, a group of connected ropes $\\lbrace v_0, v_1, \\ldots, v_{x-1} \\rbrace$ is said to form a cycle if one can rearrange the elements of $v$ so that, for each $0 \\leq i < x$, rope $v_i$ is tied to rope $v_{(i+1) \\bmod x}$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $0 \\leq M \\leq 2 \\times 10^5$\n*   $1 \\leq A_i, C_i \\leq N$\n*   $(A_i, B_i) \\neq (A_j, B_j), (C_i, D_i) \\neq (C_j, D_j)$ $(i \\neq j)$\n*   $(A_i, B_i) \\neq (C_j, D_j)$\n*   $N, M, A_i$, and $C_i$ are integers.\n*   $B_i$ is `R` or `B`, and so is $D_i$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$\n$A_1$ $B_1$ $C_1$ $D_1$\n$A_2$ $B_2$ $C_2$ $D_2$\n$\\vdots$\n$A_M$ $B_M$ $C_M$ $D_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc293_d","tags":[],"sample_group":[["5 3\n3 R 5 B\n5 R 3 B\n4 R 2 B","1 2\n\nThere are three groups of connected ropes: $\\lbrace 1 \\rbrace$, $\\lbrace 2,4 \\rbrace$, and $\\lbrace 3,5 \\rbrace$.\nThe group of ropes $\\lbrace 3,5 \\rbrace$ forms a cycle, while the groups of rope $\\lbrace 1 \\rbrace$ and ropes $\\lbrace 2,4 \\rbrace$ do not. Thus, $X = 1$ and $Y = 2$."],["7 0","0 7"],["7 6\n5 R 3 R\n7 R 4 R\n4 B 1 R\n2 R 3 B\n2 B 5 B\n1 B 7 B","2 1"]],"created_at":"2026-03-03 11:01:14"}}