#arc153f. [arc153_f]Tri-Colored Paths
[arc153_f]Tri-Colored Paths
Problem Statement
You are given a simple connected undirected graph with vertices and edges. The vertices are numbered to , and the -th edge connects vertices and .
Find the number of ways to paint each edge of in color , , or so that the following condition is satisfied, modulo .
- There is a simple path in that contains an edge in color , an edge in color , and an edge in color .
What is a simple path? A simple path is a pair of a sequence of vertices and a sequence of edges that satisfies the following:
- ;
- edge connects vertices and .
Constraints
- The given graph is simple and connected.
Input
The input is given from Standard Input in the following format:
Output
Print the number of ways to paint each edge of in color , , or so that the condition in question is satisfied, modulo .
Sample Input 1
3 3
1 2
1 3
3 2
Sample Output 1
0
Any simple path in contains two or fewer edges, so there is no way to satisfy the condition.
Sample Input 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Sample Output 2
534
Sample Input 3
6 5
1 3
4 3
5 4
4 2
1 6
Sample Output 3
144
Sample Input 4
6 7
1 2
2 3
3 1
4 5
5 6
6 4
1 6
Sample Output 4
1794