Weak nodes

2.9

7 votes
Algorithms, Approved, Depth First Search, Grammar-Verified, Graphs, Math, Medium, Recruit
Problem

You are given N nodes with the following information:

  • The nodes are connected by M bidirectional edges.
  • Each node has a value Vi associated with it.
  • A node is called a weak node if the connections between some other nodes are broken when that node is deleted and any alternate connections are not present.

Write a program to tell the number of subsets from all the possible subsets of weak nodes, which on getting their values multiplied gives a number which is divisible by all primes less than 25.

Since the answer can be large, print the answer Modulo 109+7.

Input format

  • First line: Two space-separated integers N and M
  • Second line: N space-separated integers denoting the values of the nodes
  • Next M lines: Two space-separated integers U and V denoting an edge between U and V

Output format

Print the required answer Modulo 109+7.

Constraints

1N,M5×104
1U,VN
1V109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Node numbers 3 and 5 are weak nodes. If we consider all of their subsets product then only one subset {3 , 5} which has the product 13110×17017=223092870 is divisible by all the prime numbers less than 25. Hence 1 is the answer.

Editor Image

?