Score : $400$ points
We have a simple undirected graph with $N$ vertices and $M$ edges. The vertices are numbered $1$ through $N$, and the edges are numbered $1$ through $M$.
Edge $i$ connects Vertex $A_i$ and Vertex $B_i$.
Find the number of ways to paint each vertex in this graph red, green, or blue so that the following condition is satisfied:
Here, it is not mandatory to use all the colors.
Input is given from Standard Input in the following format:
$N$ $M$ $A_1$ $B_1$ $A_2$ $B_2$ $A_3$ $B_3$ $\hspace{15pt} \vdots$ $A_M$ $B_M$
Print the answer.
3 3 1 2 2 3 3 1
6
Let $c_1, c_2, c_3$ be the colors of Vertices $1, 2, 3$ 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 $32$-bit signed integer type.