Under construction

Still being built. Things may change

Odd Degrees

Time limit1sMemory limit128 MB

Summary
Count subsets of edges of an undirected graph whose retained edges give every vertex odd degree, modulo 1e9+7.
Level

Medium7 of 10

Topics
Graph, Math, Union-find, Implementation
Solved
No attempts yet

Problem

A republic has NN towns (1≤N≤50,0001 \le N \le 50{,}000) connected by MM undirected paths (1≤M≤100,0001 \le M \le 100{,}000). The ii-th path joins two distinct towns AiA_i and BiB_i (1≤Ai≤N1 \le A_i \le N, 1≤Bi≤N1 \le B_i \le N, Ai≠BiA_i \ne B_i); no two paths connect the same pair of towns. The republic need not be connected — some pairs of towns may be unable to reach each other.

Invaders are about to take an inventory of every remaining path, so the towns want to shut some paths down. They are after a configuration in which every town is an endpoint of an odd number of the remaining paths.

Count how many subsets of paths can be kept so that every town has an odd number of remaining paths connected to it. Because this number can be very large, output it modulo 1,000,000,0071{,}000{,}000{,}007. If no such subset exists, the count is 00.

For example, consider the republic below:

1---2
 \ /
  3---4

Exactly two subsets work here. One keeps the paths 1–3, 2–3, and 3–4 (and removes 1–2): towns 1, 2, and 4 each touch one path, while town 3 touches three. The other keeps 1–2 and 3–4. The answer for this republic is therefore 22.

Input

  • Line 1: two space-separated integers NN and MM.
  • Lines 2…M+12 \dots M+1: line i+1i+1 contains two space-separated integers AiA_i and BiB_i, describing the ii-th path.

Output

  • A single integer: the number of subsets of paths whose retention leaves every town with an odd number of connected paths, taken modulo 1,000,000,0071{,}000{,}000{,}007. Output 00 if no such subset exists.

Examples3

  1. Example 1

    Input
    4 4
    1 2
    2 3
    3 1
    3 4
    
    Expected output
    2
    
  2. Example 2

    Input
    2 1
    1 2
    
    Expected output
    1
    
  3. Example 3

    Input
    1 0
    
    Expected output
    0