3 2 1 2 3 2
499122178
Let $(i, j)$ denote the action of connecting the $i$\-th red terminal and the $j$\-th blue terminal with a cable.
* For $(1,1), (2,2)$: There will be two connected components, $\lbrace 1,3 \rbrace$ and $\lbrace 2 \rbrace$, so $s=2$.
* For $(1,2), (2,1)$: The whole graph constitutes one connected component, so $s=1$.
Thus, the expected value of $s$ is $\frac{3}{2} \equiv 499122178 \pmod {998244353}$.17 5 1 1 1 1 1 1 1 1 1 1
17 $s=N$ no matter how you connect the cables.
8 10 2 4 7 1 7 6 1 4 8 1 5 1 5 2 5 8 4 6 1 3
608849831
{
"problem": {
"name": "Electric Circuit",
"description": {
"content": "You are creating an electrical circuit using $N$ parts numbered $1$ to $N$ and $M$ cables. These parts have a total of $M$ red terminals and $M$ blue terminals, with the $i$\\-th red terminal attached ",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 3000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "abc321_g"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You are creating an electrical circuit using $N$ parts numbered $1$ to $N$ and $M$ cables. These parts have a total of $M$ red terminals and $M$ blue terminals, with the $i$\\-th red terminal attached ...",
"is_translate": false,
"language": "English"
}
]
}