atcoder#ABC199D. [ABC199D] RGB Coloring 2
[ABC199D] RGB Coloring 2
Score : points
Problem Statement
We have a simple undirected graph with vertices and edges. The vertices are numbered through , and the edges are numbered through . Edge connects Vertex and Vertex . Find the number of ways to paint each vertex in this graph red, green, or blue so that the following condition is satisfied:
- two vertices directly connected by an edge are always painted in different colors.
Here, it is not mandatory to use all the colors.
Constraints
- The given graph is simple (that is, has no multi-edges and no self-loops).
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 3
1 2
2 3
3 1
6
Let be the colors of Vertices and R
, G
, B
denote red, green, blue, respectively. There are six ways to satisfy the condition:
-
RGB
-
RBG
-
GRB
-
GBR
-
BRG
-
BGR
3 0
27
Since the graph has no edge, we can freely choose the colors of the vertices.
4 6
1 2
2 3
3 4
2 4
1 3
1 4
0
There may be no way to satisfy the condition.
20 0
3486784401
The answer may not fit into the -bit signed integer type.