# Counting Graphs SOLUTIONS CNTGRP

Page Contents

### Counting Graphs SOLUTIONS CNTGRP

At some point, Tanya was examining chart hypothesis. She is extremely curious, so the accompanying issue before long struck a chord.

Locate the quantity of undirected unweighted associated basic charts with N vertices (numbered 1 through N) and M edges, with the end goal that for every I (2≤i≤N), the briefest way from vertex 1 to vertex I is special and its length is equivalent to Ai. As such, for every I (2≤i≤N), there ought to be actually one way with length Ai between vertices 1 and I, and there ought to be no ways with littler length between these vertices.

Two charts with N vertices are unmistakable in the event that we can discover two vertices u and v with the end goal that there is an edge between these vertices in one diagram, however not in the other diagram.

Since the appropriate response could be enormous, process it modulo 1,000,000,007 (109+7).

Info

The principal line of the info contains a solitary whole number T meaning the quantity of experiments. The depiction of T experiments follows.

The primary line of each experiment contains two space-isolated numbers N and M.

The subsequent line contains N−1 space-isolated whole numbers A2,A3,… ,AN.

Yield

For each experiment, print a solitary line containing one whole number ― the quantity of charts modulo 109+7.

Requirements

1≤T≤1,000

2≤N≤105

N−1≤M≤min(2⋅105,N(N−1)2)

1≤Ai≤N−1 for each legitimate I

the entirety of N over all experiments doesn’t surpass 2⋅105

the entirety of M over all experiments doesn’t surpass 2⋅105

Subtask #2 (50 focuses): unique imperatives

Model Input

4 3

1 2 1

4 6

1 2 1

3 2

Model Output

Clarification

Model case 1: The two diagrams which fulfill all conditions are: