The city of Pordenone is planning an expansion of its road network. There are towns (clearly indexed from to ) in Pordenone’s hinterland and bidirectional roads connecting some pairs of towns.
An expansion plan is any set of roads that contains the currently present roads. E. Domora, the mayor of Pordenone, cannot choose an expansion plan among all the possible ones and is in desperate need of your analytical skills.
A cluster of towns is a non-empty set of towns such that, for each and any other town , there exists a set of roads connecting (possibly indirectly) and if and only if . Note that, given a road network, there is an unique way to partition the towns in clusters.
Task
Given a road network, its Scoazza™ Score is , where is the number of clusters in which it partitions the towns; Mayor Domora is asking you to compute the sum of the Scoazza™ Scores of all possible expansion plans.
Since this number can be big, output it modulo .
Input data
The input file consists of:
- a line containing integers , .
- a line containing the integers .
- a line containing the integers .
Output data
The output file must contain a single line consisting of a single integer: the answer to the problem.
Constraints and clarifications
- for each
- All the roads are distinct.
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 17 | |
3 | 40 | |
4 | 43 | No additional constraints |
Example 1
stdin
4 3
0 1 2
1 2 0
stdout
18
Explanation
There are towns and roads already built:
- The road connecting town and town .
- The road connecting town and town .
- The road connecting town and town .
There are possible roads that can be built:
- The road connecting town and town .
- The road connecting town and town .
- The road connecting town and town .
There are possible expansion plans:
- The one in which no road is added. In this case there will be clusters: and .
- The one in which only the road connecting towns and is added. In this case there will be a single cluster: .
- etc.
Note that, following any other expansion plan will lead to a single cluster containing all the cities. The answer is hence .
Example 2
stdin
10 8
0 1 2 3 7 6 4 8
1 2 0 4 5 7 9 9
stdout
360988397
Explanation
There are towns and roads already built: