Delete and Cut Game

3.7

21 votes
Algorithms, Breadth First Search, Graphs, Probability
Problem

You are given a connected graph with nodes and edges. Two players and are playing a game with this graph. A person chooses an edge uniformly, randomly, and removes it. If the size (number of nodes in component) of two non-empty connected component created are EVEN, then wins otherwise player wins.

Find the probability of winning the game for and . The probability is of the form where  and  are both coprimes. Print .
Note: can only select the edges which divide the graph into two non-empty connected components after they are removed. If no such edge is present in the graph, then the probability to win can be 0 for both and .

Input format

  • The first line contains two space-separated integers denoting the number of nodes and edges.
  • The next lines contain two space-separated integers denoting an edge between node and node .
    Note: The graph does not have multiple edges between two vertices

Output format
Print two space-separated integers denoting the probability of winning for and respectively.

Constraints

Sample Input
6 7
1 2
2 3
3 1
4 5
5 6
6 4
1 4
Sample Output
0 1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

X can choose only edge 1-4 and B wins in that case.

Editor Image

?