#ARC153F. [ARC153F] Tri-Colored Paths

[ARC153F] Tri-Colored Paths

Score : 10001000 points

Problem Statement

You are given a simple connected undirected graph GG with NN vertices and MM edges. The vertices are numbered 11 to NN, and the ii-th edge connects vertices AiA_i and BiB_i.

Find the number of ways to paint each edge of GG in color 11, 22, or 33 so that the following condition is satisfied, modulo 998244353998244353.

  • There is a simple path in GG that contains an edge in color 11, an edge in color 22, and an edge in color 33.
What is a simple path? (v1,,vk+1)(v_1, \ldots, v_{k+1})(e1,,ek)(e_1, \ldots, e_k)- ij    vivji\neq j \implies v_i\neq v_j; - edge eie_i connects vertices viv_i and vi+1v_{i+1}.
## Constraints - 3N2×1053 \leq N\leq 2\times 10^5 - 3M2×1053 \leq M\leq 2\times 10^5 - 1Ai,BiN1 \leq A_i, B_i \leq N - The given graph is simple and connected. ## Input The input is given from Standard Input in the following format: > NN MM > > A1A_1 B1B_1 > > \vdots > > AMA_M BMB_M ## Output Print the number of ways to paint each edge of GG in color 11, 22, or 33 so that the condition in question is satisfied, modulo 998244353998244353. ```input1 3 3 1 2 1 3 3 2 ``` ```output1 0 ``` Any simple path in GG contains two or fewer edges, so there is no way to satisfy the condition. ```input2 4 6 1 2 1 3 1 4 2 3 2 4 3 4 ``` ```output2 534 ``` ```input3 6 5 1 3 4 3 5 4 4 2 1 6 ``` ```output3 144 ``` ```input4 6 7 1 2 2 3 3 1 4 5 5 6 6 4 1 6 ``` ```output4 1794 ```$$