No.3695 Same Room and Separate Rooms
タグ : / 解いたユーザー数 35
作問者 :
Problem Statement
You will divide $N$ participants into $2$ teams. There are $Q$ requests, and the $i$-th request is represented by $t_i, a_i, b_i$.
If $t_i = 0$, participants $a_i$ and $b_i$ must be on the same team; if $t_i = 1$, they must be on different teams.
Find the number of ways to divide the participants that satisfy all the requests, modulo $998244353$. If no division satisfies the requests, output $0$.
Note that either team may be empty. Also, the $2$ teams are distinguished.
Input
$N\ Q$ $t_1\ a_1\ b_1$ $\vdots$ $t_Q\ a_Q\ b_Q$
- $1 \le N \le 2 \times 10^5$
- $0 \le Q \le 2 \times 10^5$
- $t_i$ is $0$ or $1$
- $1 \le a_i \lt b_i \le N$
- All input values are integers
Output
Output the number of ways to divide the participants that satisfy all the requests, modulo $998244353$. End the output with a newline.
Sample
Sample 1
Input
4 2 0 1 2 1 3 4
Output
4
Participants $1, 2$ are on the same team, and participants $3, 4$ are on different teams. There are $2$ groups that can be decided independently, so the answer is $2^2 = 4$ ways.
Sample 2
Input
3 3 0 1 2 1 2 3 0 1 3
Output
0
If $1$ and $2$ are the same and $2$ and $3$ are different, then $1$ and $3$ should be different, but this contradicts the $3$-rd request.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。