/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
1 から N までの番号が付いた N 個の容器があります。各容器には赤い液体か青い液体が入っています。最初の状態は長さ N の文字列 S で与えられ、S の i 文字目が 1 なら容器 i には赤い液体が、0 なら青い液体が入っています。
交換装置が M 台あります。装置 j は容器 U_j と容器 V_j を接続しています。この装置を使うと、その二つの容器の内容物を丸ごと交換できます。液体が混ざることはありません。同じ容器を接続する装置や、同じ二つの容器を接続する複数の装置がある場合もあります。
高橋君は、好きな装置を選んで内容物を交換する操作を、好きな順序で何回でも行えます。一度も操作しなくてもかまいません。
操作後の各容器の色を番号順に並べた文字列として、あり得るものは何種類ありますか。答えを 998244353 で割った余りを求めてください。同じ色の液体どうしは区別せず、交換に使った装置や操作順が異なっても、各容器の色が同じなら同じ状態とします。
制約
- 1\leq N\leq200000
- 0\leq M\leq200000
- S は
0と1からなる長さ N の文字列である。 - 1\leq U_j,V_j\leq N (1\leq j\leq M)
- N,M,U_j,V_j は整数である。
入力
入力は以下の形式で標準入力から与えられます。
N M S U_1 V_1 U_2 V_2 \vdots U_M V_M
- 1 行目には、容器の個数 N と交換装置の台数 M が与えられます。
- 2 行目には、最初の色配置を表す文字列 S が与えられます。
- 続く M 行のうち j 行目には、装置 j が接続する容器の番号 U_j,V_j が与えられます。
- M=0 の場合、3 行目以降はありません。
出力
操作後の色配置としてあり得るものの種類数を 998244353 で割った余りを出力してください。
入力例 1
3 2 100 1 2 2 3
出力例 1
3
入力例 2
4 0 1010
出力例 2
1
入力例 3
6 3 110010 1 2 2 3 4 5
出力例 3
6
入力例 4
10 7 1010110010 1 2 2 3 3 4 4 5 6 7 7 8 8 9
出力例 4
60
入力例 5
1 1 1 1 1
出力例 5
1
Score : 400 pts
Problem Statement
There are N containers numbered 1 to N. Each container contains either red liquid or blue liquid. The initial state is given by a string S of length N; if the i-th character of S is 1, container i contains red liquid, and if it is 0, container i contains blue liquid.
There are M swapping devices. Device j connects container U_j and container V_j. Using this device allows you to completely swap the contents of these two containers. The liquids do not mix. There may be devices connecting the same container to itself, or multiple devices connecting the same pair of containers.
Takahashi can choose any device and swap the contents any number of times in any order. He may also choose not to perform any operations.
How many different strings can be formed by concatenating the colors of the containers in ascending order of their numbers after operations? Find the count modulo 998244353. Liquids of the same color are indistinguishable, and two states are considered the same if each container has the same color, regardless of which devices were used or the order of operations.
Constraints
- 1\leq N\leq200000
- 0\leq M\leq200000
- S is a string of length N consisting of
0and1. - 1\leq U_j,V_j\leq N (1\leq j\leq M)
- N,M,U_j,V_j are integers.
Input
The input is given from Standard Input in the following format:
N M S U_1 V_1 U_2 V_2 \vdots U_M V_M
- The first line contains the number of containers N and the number of swapping devices M.
- The second line contains the string S representing the initial color configuration.
- The j-th of the following M lines contains the container numbers U_j,V_j connected by device j.
- If M=0, there are no lines after the second line.
Output
Print the number of possible color configurations after operations, modulo 998244353.
Sample Input 1
3 2 100 1 2 2 3
Sample Output 1
3
Sample Input 2
4 0 1010
Sample Output 2
1
Sample Input 3
6 3 110010 1 2 2 3 4 5
Sample Output 3
6
Sample Input 4
10 7 1010110010 1 2 2 3 3 4 4 5 6 7 7 8 8 9
Sample Output 4
60
Sample Input 5
1 1 1 1 1
Sample Output 5
1