Under construction

Still being built. Things may change

Bi-coloring

Interview

Time limit1sMemory limit128 MB

Summary
Count the two-colorings where every edge joins different colors, or report -1 when the graph is not bipartite.
Level

Easy3 of 10

Topics
BFS, Graph
Solved
No attempts yet

Problem

You are given an undirected graph. You want to paint every vertex with one of two colors, A and B, so that the two endpoints of every edge get different colors.

Count the colorings that satisfy this condition. The two colors are distinguishable, so two colorings are different as soon as one vertex is painted differently. You do not have to use both colors.

Input

The first line contains TT, the number of test cases.

The first line of each test case contains two integers VV (1≤V≤301 \le V \le 30) and EE (0≤E≤10000 \le E \le 1000), the number of vertices and the number of edges. Each of the next EE lines contains two integers aa, bb (0≤a≤V−10 \le a \le V-1, 0≤b≤V−10 \le b \le V-1), meaning there is a bidirectional edge between vertex aa and vertex bb. There are no self loops and no duplicate edges.

Test cases may be separated by a blank line, and the last line of the input may be blank.

Output

For each test case, print on one line the number of ways to color the graph with the two colors. If the graph cannot be colored with the two colors, print -1.

Examples1

  1. Example 1

    Input
    4
    5 5
    0 1
    0 4
    1 2
    2 3
    3 0
    
    3 3
    0 1
    1 2
    2 0
    
    6 7
    0 1
    1 2
    2 3
    3 0
    4 0
    4 5
    5 1
    
    2 0
    
    Expected output
    2
    -1
    2
    4