Weak nodes

2.9

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

You are given nodes with the following information:

  • The nodes are connected by bidirectional edges.
  • Each node has a value 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 .

Since the answer can be large, print the answer Modulo .

Input format

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

Output format

Print the required answer Modulo .

Constraints



Sample Input
6 7
111 2 13110 345 17017 851
1 2
2 3
3 1
3 4
4 5
3 5
5 6
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

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

Editor Image

?