Lucky Stars Management

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

The company Lucky Stars, where Bill works as the President, has NN employees, enumerated from 1 to NN in order of their position in the company.

Bill have the employee ID 1. Any other employee, except for the President Bill, have exactly one direct supervisor. The direct supervisor of the employee ii is denoted as P_i\<iP\_i\<i. For each of NN employees the annual income of this employee is an integer A_jA\_j between 00 and 109+610^9+6.

Once Bill decided to consult with a fortune-teller who is absolutely right about the future of the company and heard something like "someday, KK mistakes will be done, and Lucky Stars management became difficult."

Each mistake is caused by exactly 1 employee, and for i=1,2,,Ni=1,2, \ldots, N the probability that the mistake is caused by employee ii is 1/N1/N (note that the mistakes are independent, i.e. it can happen that some employee caused several mistakes).

Bill held a meeting and decided to enforce the personal responsibility in case if fortune-teller was right. Bill wants to find one employee and let him pay a fine if KK types of mistakes were made by the Lucky Stars personnel at one day. The employee who pays the fine is determined according to the following rules.

  • When an employee makes a mistake, not only that employee but also the employee's direct superior, the superior's superior, and so on, are responsible (this rule includes Bill himself).
  • Therefore, among the employees who are responsible for all KK types of mistakes, the employee with the largest employee number pays the fine.
  • Let A_jA\_j be the annual salary of the employee who made the jj-th mistake for j=1,2,,Kj = 1,2,\ldots,K, and let him be fined A_1×A_2××A_KA\_1 \times A\_2 \times \ldots \times A\_K.

Bill calculated the expected value E_iE\_i of the fine paid by the employee number ii if the fortune-telling was correct, and represented it modulo 109+710^9+7.

In other words, for i=1,2,,Ni=1,2,…,N, the expected fine to be paid by employee number ii is expressed as Y_i/X_iY\_i/X\_i (where X_iX\_i and Y_iY\_i are relatively prime integers and X_iX\_i is not divisible by 109+710^9+7), then answer is Y_iY\_i div X_iX\_i modulo 109+710^9+7.

Now, you have the information about structure of the company (i.e. the value of P_iP\_i for each employee) and the values of E_iE\_i of the expected value of fines, calculated by Bill.

Please determine whether all of the obtained information is likely to be correct, and if so, find the minimum possible Bill's annual salary.

입력

The first line of the input contains two integers NN (1N21051 \le N \le 2 \cdot 10^5) and KK (1K1091 \le K \le 10^9, KK is odd).

The second line of the input contains N1N-1 integers P_2P\_2, \ldots, P_NP\_N (1P_ii11 \le P\_i \le i-1) --- the number P_iP\_i of the direct supervisor of the employee ii. If N=1N=1, the second line is empty.

The third line of the input contains NN integers E_iE\_i --- the calculated expected fines for ii-th employee (0E_i109+60 \le E\_i \le 10^9+6).

출력

If the calculation is definitely wrong, print 1-1. Otherwise print one integer --- the minimum possible annual salary of Bill.