#K85047. Trading Scenarios on Island Networks
Trading Scenarios on Island Networks
Trading Scenarios on Island Networks
In this problem, you are given a network of islands connected by bridges. Each island may either engage in trading or keep its own item. However, trading happens in groups: if two or more islands are connected (directly or indirectly), they must decide together whether to participate in trading. For each connected component with at least two islands, there are two distinct trading decisions (either all trade or none trade). For isolated islands (components of size 1), the decision is fixed (only one possibility).
Formally, given (n) islands and (m) bridges connecting them, let the number of connected components with at least two islands be (k). The total number of distinct trading scenarios is:
[ \text{result} = 2^{k} \pmod{10^9+7} ]
Your task is to compute the total number of trading scenarios.
inputFormat
The first line contains two integers (n) and (m) (the number of islands and the number of bridges, respectively). Each of the next (m) lines contains two integers (u) and (v) (0-indexed) representing a bridge between islands (u) and (v).
outputFormat
Output a single integer representing the total number of distinct trading scenarios modulo (10^9+7).## sample
6 3
0 1
2 3
4 5
8
</p>