Delete and Cut Game
Practice
3.7 (21 votes)
Algorithms
Breadth first search
Graphs
Probability
Problem
72% Success 8307 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a connected graph with \(N\) nodes and \(M\) edges. Two players \(A\) and \(B\) are playing a game with this graph. A person \(X\) 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 \(A\) wins otherwise player \(B\) wins.

Find the probability of winning the game for \(A\) and \(B\). The probability is of the \(\frac P Q\) form where \(P\) and \(Q\) are both coprimes. Print \(PQ^{-1}\ modulo\ 1000000007\).
Note: \(X\) 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 \(A\) and \(B\).

Input format

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

Output format
Print two space-separated integers denoting the probability of winning for \(A\) and \(B\) respectively.

Constraints
\(1 \le  N,\ M \le 1e5\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
10 votes
Tags:
AlgorithmsBreadth First SearchGraphsMedium
Points:30
8 votes
Tags:
GraphsAlgorithmsBreadth-first search
Points:30
16 votes
Tags:
AlgorithmsBreadth First SearchGraphsMedium