問題一覧 > 通常問題

No.3695 Same Room and Separate Rooms

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 5509 / 自分の提出
問題文最終更新日: 2026-09-09 19:15:19
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
チーム機能テストコンテスト (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。